Skip to content

Commit 1ff6b14

Browse files
committed
fixup! Add a new sdn controller plugin
Signed-off-by: David Morel <david.morel@vates.tech>
1 parent 16c23d6 commit 1ff6b14

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

SOURCES/etc/xapi.d/plugins/sdncontroller.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def __init__(self, args):
3131
self.values = {}
3232
self.errors = []
3333

34-
def parse_bridge(self, args):
34+
def parse_bridge(self):
3535
BRIDGE_REGEX = re.compile(r"\b\w+\d+\b")
36-
bridge = args.get("bridge")
36+
bridge = self.args.get("bridge")
3737

3838
if bridge is None:
3939
log_and_raise_error(E_PARSER, "bridge parameter is missing")
@@ -43,9 +43,9 @@ def parse_bridge(self, args):
4343

4444
return bridge
4545

46-
def parse_mac(self, args):
46+
def parse_mac(self):
4747
MAC_REGEX = re.compile(r"^([0-9A-Fa-f]{2}:){5}([0-9A-Fa-f]{2})$")
48-
mac_addr = args.get("mac")
48+
mac_addr = self.args.get("mac")
4949

5050
if mac_addr is None:
5151
return None
@@ -55,12 +55,12 @@ def parse_mac(self, args):
5555

5656
return mac_addr
5757

58-
def parse_iprange(self, args):
58+
def parse_iprange(self):
5959
IPRANGE_REGEX = re.compile(
6060
r"^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}"
6161
r"(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(/\d{1,2})?$"
6262
)
63-
ip_range = args.get("iprange")
63+
ip_range = self.args.get("iprange")
6464

6565
if ip_range is None:
6666
log_and_raise_error(E_PARSER, "ip range parameter is missing")
@@ -70,8 +70,8 @@ def parse_iprange(self, args):
7070

7171
return ip_range
7272

73-
def parse_direction(self, args):
74-
direction = args.get("direction")
73+
def parse_direction(self):
74+
direction = self.args.get("direction")
7575

7676
if direction is None:
7777
log_and_raise_error(E_PARSER, "direction parameter is missing")
@@ -85,8 +85,8 @@ def parse_direction(self, args):
8585

8686
return (has_to, has_from)
8787

88-
def parse_protocol(self, args):
89-
protocol = args.get("protocol")
88+
def parse_protocol(self):
89+
protocol = self.args.get("protocol")
9090

9191
if protocol is None:
9292
log_and_raise_error(E_PARSER, "protocol parameter is missing")
@@ -98,8 +98,8 @@ def parse_protocol(self, args):
9898

9999
return protocol
100100

101-
def parse_port(self, args):
102-
port = args.get("port")
101+
def parse_port(self):
102+
port = self.args.get("port")
103103
if port is None:
104104
return None
105105

@@ -111,8 +111,8 @@ def parse_port(self, args):
111111
except ValueError:
112112
log_and_raise_error(E_PARSER, "'{}' is not a valid port".format(port))
113113

114-
def parse_allow(self, args):
115-
allow = args.get("allow")
114+
def parse_allow(self):
115+
allow = self.args.get("allow")
116116
if allow is None:
117117
log_and_raise_error(E_PARSER, "allow parameter is missing")
118118

@@ -124,8 +124,8 @@ def parse_allow(self, args):
124124

125125
return False
126126

127-
def parse_priority(self, args):
128-
priority = args.get("priority")
127+
def parse_priority(self):
128+
priority = self.args.get("priority")
129129
if priority is None:
130130
return None
131131

@@ -141,7 +141,7 @@ def read(self, key, parse_fn, dests=None):
141141
# parse_fn can return a single value or a tuple of values.
142142
# In this case we are expecting dests to match the expected
143143
# returned tuple
144-
val = parse_fn(self.args)
144+
val = parse_fn()
145145

146146
if dests is not None:
147147
if not isinstance(val, tuple):
@@ -298,7 +298,7 @@ def dump_flows(_session, args):
298298

299299
parser = Parser(args)
300300
try:
301-
bridge = parser.parse_bridge(args)
301+
bridge = parser.parse_bridge()
302302
except XenAPIPlugin.Failure as e:
303303
log_and_raise_error(E_PARSER, "dump_flows: Failed to get parameters: {}".format(e.params[1]))
304304

tests/test_sdn-controller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def parser_test(method, params):
3030
exc = params['exception']
3131
if exc:
3232
with pytest.raises(exc['type']) as e:
33-
ret = method(params['input'])
33+
ret = method()
3434
assert e.value.params[0] == exc['code']
3535
assert e.value.params[1] == exc['text']
3636
else:
37-
ret = method(params['input'])
37+
ret = method()
3838
assert ret == params['result']
3939

4040
class TestSdnControllerParser:

0 commit comments

Comments
 (0)