Skip to content

Commit 98591db

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Change authentication method for Mellanox sdn controller"
2 parents 2148a80 + b552117 commit 98591db

File tree

8 files changed

+72
-109
lines changed

8 files changed

+72
-109
lines changed

devstack/README.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@
3535

3636
[[post-config|/etc/neutron/plugins/ml2/ml2_conf.ini]]
3737
[sdn]
38-
url = http://<sdn_provider_ip>/neo
38+
url = http://<sdn_provider_ip>/ufmRestV3
3939
domain = cloudx
40-
username = admin
41-
password = admin
40+
token = abcdef
4241

4342
5) run ``stack.sh``

etc/neutron/plugins/ml2/ml2_conf_sdn.ini

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,18 @@
33
[sdn]
44
# (StrOpt) mandatory param: SDN REST URL
55
# If this is not set then no HTTP requests will be made.
6-
# Example: url = http://10.209.25.201/neo/
6+
# Example: url = http://10.209.25.201/ufmRestV3/
77
# url =
88

99
# (StrOpt) mandatory param: Cloud domain name in SDN provider
1010
# This is an optional parameter, default value is cloudx
1111
# Example: domain = cloudx
1212
# domain =
1313

14-
# (StrOpt) mandatory param: Username for HTTP basic authentication
14+
# (StrOpt) mandatory param: Token for HTTP basic authentication
1515
# to SDN Provider.
16-
# Example: username = admin
17-
# username =
18-
19-
# (StrOpt) mandatory param: Password for HTTP basic authentication
20-
# to SDN Provider.
21-
# Example: password = admin
22-
# password =
16+
# Example: token = abcdef
17+
# token =
2318

2419
# (IntOpt) Timeout in seconds to wait for SDN Provider HTTP request completion.
2520
# This is an optional parameter, default value is 10 seconds.
@@ -61,4 +56,4 @@
6156
# that it will send notification. * means all physical_networks
6257
#
6358
# physical_networks = *
64-
# Example: physical_networks = datacenter1, datacenter3
59+
# Example: physical_networks = datacenter1, datacenter3

networking_mlnx/journal/journal.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _sync_pending_rows(self, session, exit_after_run):
126126
{'operation': row.operation, 'type': row.object_type,
127127
'uuid': row.object_uuid})
128128

129-
# Add code to sync this to NEO
129+
# Add code to sync this to SDN controller
130130
urlpath = sdn_utils.strings_to_url(row.object_type)
131131
if row.operation != sdn_const.POST:
132132
urlpath = sdn_utils.strings_to_url(urlpath, row.object_uuid)
@@ -173,7 +173,7 @@ def _sync_pending_rows(self, session, exit_after_run):
173173
except (sdn_exc.SDNConnectionError, sdn_exc.SDNLoginError):
174174
# Log an error and raise the retry count. If the retry count
175175
# exceeds the limit, move it to the failed state.
176-
LOG.error("Cannot connect to the NEO Controller")
176+
LOG.error("Cannot connect to the SDN Controller")
177177
db.update_pending_db_row_retry(session, row,
178178
self._row_retry_count)
179179
# Break out of the loop and retry with the next
@@ -182,7 +182,7 @@ def _sync_pending_rows(self, session, exit_after_run):
182182

183183
def _sync_progress_rows(self, session):
184184
# 1. get all progressed job
185-
# 2. get status for NEO
185+
# 2. get status for SDN Controller
186186
# 3. Update status if completed/failed
187187
LOG.debug("sync_progress_rows operation walking database")
188188
rows = db.get_all_monitoring_db_row_by_oldest(session)
@@ -204,13 +204,13 @@ def _sync_progress_rows(self, session):
204204
session, row, sdn_const.COMPLETED)
205205
continue
206206
if job_status in ("Pending", "Running"):
207-
LOG.debug("NEO Job id %(job_id)s is %(status)s "
208-
"continue monitoring",
207+
LOG.debug("SDN Controller Job id %(job_id)s is "
208+
"%(status)s continue monitoring",
209209
{'job_id': row.job_id,
210210
'status': job_status})
211211
continue
212-
LOG.error("NEO Job id %(job_id)s, failed with"
213-
" %(status)s",
212+
LOG.error("SDN Controller Job id %(job_id)s, "
213+
"failed with %(status)s",
214214
{'job_id': row.job_id,
215215
'status': job_status})
216216
db.update_db_row_state(
@@ -219,14 +219,14 @@ def _sync_progress_rows(self, session):
219219
LOG.error("failed to extract response for job"
220220
"id %s", row.job_id)
221221
else:
222-
LOG.error("NEO Job id %(job_id)s, failed with "
222+
LOG.error("SDN Controller Job id %(job_id)s, failed with "
223223
"%(status)s",
224224
{'job_id': row.job_id, 'status': job_status})
225225
db.update_db_row_state(session, row, sdn_const.PENDING)
226226

227227
except (sdn_exc.SDNConnectionError, sdn_exc.SDNLoginError):
228228
# Don't raise the retry count, just log an error
229-
LOG.error("Cannot connect to the NEO Controller")
229+
LOG.error("Cannot connect to the SDN Controller")
230230
db.update_db_row_state(session, row, sdn_const.PENDING)
231231
# Break out of the loop and retry with the next
232232
# timer interval

networking_mlnx/plugins/ml2/drivers/sdn/client.py

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,29 @@
3131

3232
class SdnRestClient(object):
3333

34-
MANDATORY_ARGS = ('url', 'username', 'password')
34+
MANDATORY_ARGS = ('url', 'token')
3535

3636
@classmethod
3737
def create_client(cls):
3838
return cls(
3939
cfg.CONF.sdn.url,
4040
cfg.CONF.sdn.domain,
41-
cfg.CONF.sdn.username,
42-
cfg.CONF.sdn.password,
4341
cfg.CONF.sdn.timeout,
4442
cfg.CONF.sdn.cert_verify,
45-
cfg.CONF.sdn.cert_path)
43+
cfg.CONF.sdn.cert_path,
44+
cfg.CONF.sdn.token)
4645

47-
def __init__(self, url, domain, username, password, timeout,
48-
verify, cert_path):
46+
def __init__(self, url, domain, timeout,
47+
verify, cert_path, token):
4948
self.url = url
5049
self.domain = domain
5150
self.timeout = timeout
52-
self.username = username
53-
self.password = password
51+
self.token = token
5452
self._validate_mandatory_params_exist()
5553
self.url.rstrip("/")
5654
self.verify = verify
55+
self.headers = {"Authorization": "Basic {0}".format(self.token),
56+
**sdn_const.JSON_HTTP_HEADER}
5757
if verify:
5858
self.verify = self._get_cert(cert_path)
5959

@@ -73,24 +73,6 @@ def _validate_mandatory_params_exist(self):
7373
raise cfg.RequiredOptError(
7474
arg, cfg.OptGroup(sdn_const.GROUP_OPT))
7575

76-
def _get_session(self):
77-
login_url = sdn_utils.strings_to_url(str(self.url), "login")
78-
login_data = "username=%s&password=%s" % (self.username,
79-
self.password)
80-
login_headers = sdn_const.LOGIN_HTTP_HEADER
81-
try:
82-
session = requests.session()
83-
session.verify = self.verify
84-
LOG.debug("Login to SDN Provider. Login URL %(url)s",
85-
{'url': login_url})
86-
r = session.request(sdn_const.POST, login_url, data=login_data,
87-
headers=login_headers, timeout=self.timeout)
88-
LOG.debug("request status: %d", r.status_code)
89-
r.raise_for_status()
90-
except Exception as e:
91-
raise sdn_exc.SDNLoginError(login_url=login_url, msg=e)
92-
return session
93-
9476
def get(self, urlpath='', data=None):
9577
urlpath = sdn_utils.strings_to_url(self.url, urlpath)
9678
return self.request(sdn_const.GET, urlpath, data)
@@ -109,13 +91,12 @@ def delete(self, urlpath='', data=None):
10991

11092
def request(self, method, urlpath='', data=None):
11193
data = jsonutils.dumps(data, indent=2) if data else None
112-
session = self._get_session()
113-
11494
LOG.debug("Sending METHOD %(method)s URL %(url)s JSON %(data)s",
11595
{'method': method, 'url': urlpath, 'data': data})
116-
return self._check_response(session.request(
117-
method, url=str(urlpath), headers=sdn_const.JSON_HTTP_HEADER,
118-
data=data, timeout=self.timeout), method)
96+
97+
return self._check_response(requests.request(
98+
method, url=str(urlpath), headers=self.headers,
99+
data=data, verify=self.verify, timeout=self.timeout), method)
119100

120101
def _check_response(self, response, method):
121102
try:

networking_mlnx/plugins/ml2/drivers/sdn/config.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,10 @@
3030
"(for example: cloudx)"),
3131
default='cloudx'
3232
),
33-
cfg.StrOpt('username',
34-
help=_("HTTP username for authentication."),
35-
),
36-
cfg.StrOpt('password',
37-
help=_("HTTP password for authentication."),
33+
cfg.StrOpt('token',
34+
help=_("HTTPS token for authentication."),
3835
secret=True,
39-
default='123456'
36+
default="abcdef",
4037
),
4138
cfg.IntOpt('timeout',
4239
help=_("HTTP timeout in seconds."),
@@ -81,7 +78,7 @@
8178
"conjuction with bind_normal_ports. "
8279
"The list must be a subset of physical_networks")),
8380
cfg.BoolOpt('cert_verify',
84-
default="True",
81+
default="False",
8582
help=_("Use certificates to verify connections.")),
8683
cfg.StrOpt('cert_path',
8784
default="",

networking_mlnx/plugins/ml2/drivers/sdn/sdn_mech_driver.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def update_port_precommit(self, context):
256256

257257
vnic_type = port_dic[portbindings.VNIC_TYPE]
258258
# Check if we get a client id after binding the bare metal port,
259-
# and report the port to neo
259+
# and report the port to sdn controller
260260
if vnic_type == portbindings.VNIC_BAREMETAL:
261261
# Ethernet Case
262262
link__info = self._get_local_link_information(port_dic)

networking_mlnx/tests/unit/ml2/drivers/sdn/test_client.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_mandatory_args(self):
5656

5757
def test_cert_verify_default(self):
5858
test_client = client.SdnRestClient.create_client()
59-
self.assertEqual(True, test_client.verify)
59+
self.assertEqual(False, test_client.verify)
6060

6161
def test_cert_verify_true(self):
6262
self.conf_fixture.config(cert_verify=True,
@@ -171,10 +171,7 @@ def test_delete(self, mocked_request):
171171
expected_url,
172172
None)
173173

174-
@mock.patch('networking_mlnx.plugins.ml2.drivers.'
175-
'sdn.client.SdnRestClient._get_session',
176-
return_value=mock.Mock())
177-
def test_request_bad_data(self, mocked_get_session):
174+
def test_request_bad_data(self):
178175
# non serialized json data
179176
data = self
180177
self.assertRaises(ValueError,

0 commit comments

Comments
 (0)