From: Andrew Grimberg Date: Tue, 10 Jul 2018 21:59:24 +0000 (-0700) Subject: Cleanup nexus repo command for Python 3 X-Git-Tag: v0.14.0~6 X-Git-Url: https://gerrit.linuxfoundation.org/infra/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F17%2F11717%2F5;p=releng%2Flftools.git Cleanup nexus repo command for Python 3 The original Nexus repo sub-command was written for Python 2 and needs to be updated to work properly under Python 3. Change-Id: I5558f833f4fc213e8eea64fc5a53ebcf1714d7be Signed-off-by: Andrew Grimberg --- diff --git a/lftools/nexus/__init__.py b/lftools/nexus/__init__.py index 67d5fdb9..5501e8ba 100644 --- a/lftools/nexus/__init__.py +++ b/lftools/nexus/__init__.py @@ -70,10 +70,13 @@ class Nexus: } } - json_data = json.dumps(target, encoding='latin-1') + json_data = json.dumps(target).encode(encoding='latin-1') r = requests.post(url, auth=self.auth, headers=self.headers, data=json_data) + if r.status_code != requests.codes.created: + raise Exception("Target not created for '{}', code '{}'".format(name, r.status_code)) + return r.json()['data']['id'] def get_priv(self, name, priv): @@ -115,8 +118,12 @@ class Nexus: } } - json_data = json.dumps(privileges, encoding='latin-1') - privileges = requests.post(url, auth=self.auth, headers=self.headers, data=json_data).json() + json_data = json.dumps(privileges).encode(encoding='latin-1') + r = requests.post(url, auth=self.auth, headers=self.headers, data=json_data) + privileges = r.json() + + if r.status_code != requests.codes.created: + raise Exception("Privilege not created for '{}', code '{}'".format(name, r.status_code)) return privileges['data'][0]['id'] @@ -148,10 +155,13 @@ class Nexus: } } - json_data = json.dumps(role, encoding='latin-1') + json_data = json.dumps(role).encode(encoding='latin-1') r = requests.post(url, auth=self.auth, headers=self.headers, data=json_data) + if r.status_code != requests.codes.created: + raise Exception("Role not created for '{}', code '{}'".format(name, r.status_code)) + return r.json()['data']['id'] def get_user(self, user_id): @@ -190,9 +200,12 @@ class Nexus: for role in extra_roles: user['data']['roles'].append(self.get_role(role)) - json_data = json.dumps(user, encoding='latin-1') + json_data = json.dumps(user).encode(encoding='latin-1') + + user = requests.post(url, auth=self.auth, headers=self.headers, data=json_data) - requests.post(url, auth=self.auth, headers=self.headers, data=json_data) + if user.status_code != requests.codes.created: + raise Exception("User not created for '{}', code '{}'".format(name, user.status_code)) def get_repo_group(self, name): """Get the repository ID for a repo group that has a specific name.""" @@ -220,6 +233,6 @@ class Nexus: 'data': data } - json_data = json.dumps(repo, encoding='latin-1') + json_data = json.dumps(repo).encode(encoding='latin-1') requests.put(url, auth=self.auth, headers=self.headers, data=json_data)