From e055f8b0cc63fbee4581255770bfb69ff21c9414 Mon Sep 17 00:00:00 2001 From: Dmitry Sutyagin Date: Mon, 19 Sep 2016 17:33:26 +0300 Subject: [PATCH] Fix: fuel CLI auth, fuel CLI for 9.0+ Change-Id: I1828c505fe6bf41a73d08f57b72af55c0182acab --- doc/source/exitcodes.rst | 1 + timmy/cli.py | 4 ++++ timmy/nodes.py | 38 +++++++++++++++++++++++++++++--------- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/doc/source/exitcodes.rst b/doc/source/exitcodes.rst index 6f73747..fea0620 100644 --- a/doc/source/exitcodes.rst +++ b/doc/source/exitcodes.rst @@ -15,3 +15,4 @@ Exit Codes * `109` - subprocess (one of the node execution processes) exited with a Python exception. * `110` - unable to create a directory. * `111` - ip address must be defined for Node instance. +* `112` - one of the two parameters **fuel_user** or **fuel_pass** specified without the other. diff --git a/timmy/cli.py b/timmy/cli.py index 0553270..93cb453 100755 --- a/timmy/cli.py +++ b/timmy/cli.py @@ -216,6 +216,10 @@ def main(argv=None): conf['fuel_user'] = args.fuel_user if args.fuel_pass: conf['fuel_pass'] = args.fuel_pass + if any([args.fuel_user and not args.fuel_pass, + args.fuel_pass and not args.fuel_user]): + logger.critical('You must specify both --fuel-user and --fuel-pass') + exit(112) if args.fuel_token: conf['fuel_api_token'] = args.fuel_token conf['fuelclient'] = False diff --git a/timmy/nodes.py b/timmy/nodes.py index f6cd8c8..12c85c2 100644 --- a/timmy/nodes.py +++ b/timmy/nodes.py @@ -560,7 +560,7 @@ class NodeManager(object): self.logger.info('Setup fuelclient instance') if FUEL_10: args = {'host': self.conf['fuel_ip'], - 'port': self.conf['fuel_port']} + 'port': self.conf['fuel_api_port']} if self.conf['fuel_user']: args['os_username'] = self.conf['fuel_user'] if self.conf['fuel_pass']: @@ -590,6 +590,7 @@ class NodeManager(object): if (not self.get_nodes_fuelclient() and not self.get_nodes_api() and not self.get_nodes_cli()): + self.logger.critical('Failed to retrieve node information.') sys.exit(105) self.nodes_init() self.nodes_check_access() @@ -858,6 +859,7 @@ class NodeManager(object): pass def get_nodes_api(self): + return False self.logger.info('using API to get nodes json') nodes_json = self.get_api_request('nodes') if nodes_json: @@ -869,19 +871,37 @@ class NodeManager(object): def get_nodes_cli(self): self.logger.info('using CLI to get nodes json') fuelnode = self.nodes[self.conf['fuel_ip']] - fuel_node_cmd = ('fuel node list --json --user %s --password %s' % - (self.conf['fuel_user'], - self.conf['fuel_pass'])) + o_auth = n_auth = '' + entropy = bool(self.conf['fuel_user']) + bool(self.conf['fuel_pass']) + if entropy == 2: + # auth for Fuel up to 8.0 + o_auth = '--user %s --password %s' % (self.conf['fuel_user'], + self.conf['fuel_pass']) + # Fuel 9.0+ + n_auth = 'OS_USERNAME=%s OS_PASSWORD=%s' % (self.conf['fuel_user'], + self.conf['fuel_pass']) + elif entropy == 1: + self.logger.warning('Must specify both fuel_user and fuel_pass') + cmd = 'bash -c "%s fuel node --json"' % n_auth nodes_json, err, code = tools.ssh_node(ip=fuelnode.ip, - command=fuel_node_cmd, + command=cmd, ssh_opts=fuelnode.ssh_opts, timeout=fuelnode.timeout, prefix=fuelnode.prefix) if code != 0: - self.logger.warning(('NodeManager: cannot get ' - 'fuel node list from CLI: %s') % err) - self.nodes_json = None - return False + self.logger.warning(('NodeManager: cannot get fuel node list from' + ' CLI, will fallback. Error: %s') % err) + cmd = 'bash -c "fuel %s node --json"' % o_auth + nodes_json, err, code = tools.ssh_node(ip=fuelnode.ip, + command=cmd, + ssh_opts=fuelnode.ssh_opts, + timeout=fuelnode.timeout, + prefix=fuelnode.prefix) + if code != 0: + self.logger.warning(('NodeManager: cannot get ' + 'fuel node list from CLI: %s') % err) + self.nodes_json = None + return False self.nodes_json = json.loads(nodes_json) return True