def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.baremetal result = [] for node in client.node.list(detail=True, maintenance=False): if node.provision_state not in ('active', 'available'): continue caps = utils.node_get_capabilities(node) profile = caps.get('profile') possible_profiles = [k[:-len(POSTFIX)] for k, v in caps.items() if k.endswith(POSTFIX) and v.lower() in ('1', 'true')] # sorting for convenient display and testing possible_profiles.sort() result.append((node.uuid, node.name or '', node.provision_state, profile, ', '.join(possible_profiles))) return ( ("Node UUID", "Node Name", "Provision State", "Current Profile", "Possible Profiles"), result )
def test_assign_profiles_dry_run(self): self.nodes[:] = [self._get_fake_node(possible_profiles=['compute']), self._get_fake_node(possible_profiles=['control']), self._get_fake_node(possible_profiles=['compute'])] self._test(0, 1, dry_run=True) self.assertFalse(self.bm_client.node.update.called) actual_profiles = [utils.node_get_capabilities(node).get('profile') for node in self.nodes] self.assertEqual([None] * 3, actual_profiles)
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) bm_client = self.app.client_manager.baremetal compute_client = self.app.client_manager.compute hypervisors = {h.hypervisor_hostname: h for h in compute_client.hypervisors.list() if h.hypervisor_type == 'ironic'} result = [] maintenance = None if parsed_args.all else False for node in bm_client.node.list(detail=True, maintenance=maintenance): error = '' if node.provision_state not in ('active', 'available'): error = "Provision state %s" % node.provision_state elif node.power_state in (None, 'error'): error = "Power state %s" % node.power_state elif node.maintenance: error = "Maintenance" else: try: hypervisor = hypervisors[node.uuid] except KeyError: error = 'No hypervisor record' else: if hypervisor.status != 'enabled': error = 'Compute service disabled' elif hypervisor.state != 'up': error = 'Compute service down' if error and not parsed_args.all: continue caps = utils.node_get_capabilities(node) profile = caps.get('profile') possible_profiles = [k[:-len(POSTFIX)] for k, v in caps.items() if k.endswith(POSTFIX) and v.lower() in ('1', 'true')] # sorting for convenient display and testing possible_profiles.sort() record = (node.uuid, node.name or '', node.provision_state, profile, ', '.join(possible_profiles)) if parsed_args.all: record += (error,) result.append(record) cols = ("Node UUID", "Node Name", "Provision State", "Current Profile", "Possible Profiles") if parsed_args.all: cols += ('Error',) return (cols, result)
def test_assign_profiles(self): self.nodes[:] = [self._get_fake_node(possible_profiles=['compute']), self._get_fake_node(possible_profiles=['control']), self._get_fake_node(possible_profiles=['compute'])] # one warning for a redundant node self._test(0, 1, assign_profiles=True) self.assertEqual(2, self.bm_client.node.update.call_count) actual_profiles = [utils.node_get_capabilities(node).get('profile') for node in self.nodes] actual_profiles.sort(key=lambda x: str(x)) self.assertEqual([None, 'compute', 'control'], actual_profiles)
def test_assign_profiles_not_enough(self): self.nodes[:] = [self._get_fake_node(possible_profiles=['compute']), self._get_fake_node(possible_profiles=['compute']), self._get_fake_node(possible_profiles=['compute'])] self._test(1, 1, assign_profiles=True) # no node update for failed flavor self.assertEqual(1, self.bm_client.node.update.call_count) actual_profiles = [utils.node_get_capabilities(node).get('profile') for node in self.nodes] actual_profiles.sort(key=lambda x: str(x)) self.assertEqual([None, None, 'compute'], actual_profiles)
def test_assign_profiles_multiple_options(self): self.nodes[:] = [self._get_fake_node(possible_profiles=['compute', 'control']), self._get_fake_node(possible_profiles=['compute', 'control'])] self._test(0, 0, assign_profiles=True) self.assertEqual(2, self.bm_client.node.update.call_count) actual_profiles = [utils.node_get_capabilities(node).get('profile') for node in self.nodes] actual_profiles.sort(key=lambda x: str(x)) self.assertEqual(['compute', 'control'], actual_profiles)
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) client = self.app.client_manager.baremetal result = [] for node in client.node.list(detail=True, maintenance=False): if node.provision_state not in ('active', 'available'): continue caps = utils.node_get_capabilities(node) profile = caps.get('profile') possible_profiles = [ k[:-len(POSTFIX)] for k, v in caps.items() if k.endswith(POSTFIX) and v.lower() in ('1', 'true') ] # sorting for convenient display and testing possible_profiles.sort() result.append((node.uuid, node.name or '', node.provision_state, profile, ', '.join(possible_profiles))) return (("Node UUID", "Node Name", "Provision State", "Current Profile", "Possible Profiles"), result)
def take_action(self, parsed_args): self.log.debug("take_action(%s)" % parsed_args) self.bm_client = self.app.client_manager.baremetal with open(parsed_args.file, 'r') as fp: self.ready_state_config = json.load(fp) drac_nodes = [] for node in self.bm_client.node.list(detail=True): if 'drac' not in node.driver: continue selected_profile = utils.node_get_capabilities(node).get('profile') if selected_profile is None: continue drac_nodes.append((node, selected_profile)) changed_nodes = self._configure_bios(drac_nodes) self._apply_changes(changed_nodes) self._change_power_state([node for node, profile in drac_nodes], 'off')
def test_no_capabilities(self): node = mock.Mock(properties={}) self.assertEqual({}, utils.node_get_capabilities(node))
def test_with_capabilities(self): node = mock.Mock(properties={'capabilities': 'x:y,foo:bar'}) self.assertEqual({ 'x': 'y', 'foo': 'bar' }, utils.node_get_capabilities(node))
def test_with_capabilities(self): node = mock.Mock(properties={'capabilities': 'x:y,foo:bar'}) self.assertEqual({'x': 'y', 'foo': 'bar'}, utils.node_get_capabilities(node))