def test_list_servers(self): server_id = self.stack.server_id for server in nova.list_servers(): if server_id == server.id: break else: self.fail('Server {} not found'.format(server_id))
def get_vms_table(): """populate a dataframe with vm host,id,status""" vms_data = [(vm._info[ # pylint: disable=W0212 'OS-EXT-SRV-ATTR:hypervisor_hostname'], vm.id, vm.status) for vm in nova.list_servers()] vms_df = pandas.DataFrame(vms_data, columns=['vm_host', 'vm_id', 'vm_state']) return vms_df
def get_running_servers(self): servers_to_reactivate = list() for server in nova.list_servers(): server_hyp = getattr(server, 'OS-EXT-SRV-ATTR:' 'hypervisor_hostname').split('.', 1)[0] if self.name == server_hyp and server.status != 'SHUTOFF': servers_to_reactivate.append(server) LOG.info(f'Servers to restart after reboot: {servers_to_reactivate}') return servers_to_reactivate
def wait_for_all_instances_status(status, timeout=None): """wait for all instances for a certain status or raise an exception""" for instance in nova.list_servers(): nova.wait_for_server_status(server=instance.id, status=status, timeout=timeout) instance_info = 'instance {nova_instance} is {state} on {host}'.format( nova_instance=instance.name, state=status, host=instance._info[ # pylint: disable=W0212 'OS-EXT-SRV-ATTR:hypervisor_hostname']) LOG.info(instance_info)
def test_servers_creation(self): all_servers_ids = {server.id for server in nova.list_servers()} stacks = tests.test_servers_creation() self.assertEqual(2, len(stacks)) pid = os.getpid() for i, stack in enumerate(stacks): self.assertIsInstance(stack, tests.TestServerCreationStack) class_name = tobiko.get_fixture_name(tests.TestServerCreationStack) self.assertEqual(f"{class_name}-{pid}-{i}", stack.stack_name) self.assertNotIn(stack.server_id, all_servers_ids) self.assertEqual('ACTIVE', nova.get_server(stack.server_id).status)
def stop_all_instances(): """try to start all stopped overcloud instances""" for instance in nova.list_servers(): activated_instance = nova.shutoff_server(instance) time.sleep(3) instance_info = 'instance {nova_instance} is {state} on {host}'.format( nova_instance=activated_instance.name, state=activated_instance.status, host=activated_instance._info[ # pylint: disable=W0212 'OS-EXT-SRV-ATTR:hypervisor_hostname']) LOG.info(instance_info) if activated_instance.status != 'SHUTOFF': tobiko.fail(instance_info)
def test_servers_creation(stack=TestServerCreationStack, number_of_servers=2) -> \ tobiko.Selection[_nova.ServerStackFixture]: initial_servers_ids = {server.id for server in nova.list_servers()} pid = os.getpid() fixture_obj = tobiko.get_fixture_class(stack) # Get list of server stack instances fixtures: tobiko.Selection[_nova.ServerStackFixture] = tobiko.select( tobiko.get_fixture(fixture_obj, fixture_id=f'{pid}-{i}') for i in range(number_of_servers or 1)) test_case = tobiko.get_test_case() # Check fixtures types for fixture in fixtures: test_case.assertIsInstance(fixture, _nova.ServerStackFixture) # Delete all servers stacks for fixture in fixtures: tobiko.cleanup_fixture(fixture) # Create all servers stacks for fixture in fixtures: tobiko.use_fixture(fixture) # Check every server ID is unique and new server_ids = {fixture.server_id for fixture in fixtures} test_case.assertEqual(number_of_servers or 1, len(server_ids)) test_case.assertFalse(server_ids & initial_servers_ids) # sleep for 20 sec , ensure no race condition with ssh time.sleep(20) # Test SSH connectivity to floating IP address for fixture in fixtures: test_case.assertTrue(sh.get_hostname(ssh_client=fixture.ssh_client)) # Test pinging to floating IP address ping.assert_reachable_hosts(fixture.floating_ip_address for fixture in fixtures) return fixtures
def list_overcloud_nodes(**params): session = undercloud.undercloud_keystone_session() client = nova.get_nova_client(session=session) return nova.list_servers(client=client, **params)
def test_undercloud_keystone_session(self): session = tripleo.undercloud_keystone_session() client = nova.get_nova_client(session=session) overcloud_nodes = nova.list_servers(client=client) self.assertTrue(overcloud_nodes)