Ejemplo n.º 1
0
    def test__init(self, mock_cloud, mock_config):
        mock_config.return_value.get_all_clouds.return_value = [{}]

        inv = inventory.OpenStackInventory()

        mock_config.assert_called_once_with(config_files=loader.CONFIG_FILES)
        self.assertIsInstance(inv.clouds, list)
        self.assertEqual(1, len(inv.clouds))
        self.assertTrue(mock_config.return_value.get_all_clouds.called)
Ejemplo n.º 2
0
    def test__init_one_cloud(self, mock_cloud, mock_config):
        mock_config.return_value.get_one_cloud.return_value = [{}]

        inv = inventory.OpenStackInventory(cloud='supercloud')

        mock_config.assert_called_once_with(
            config_files=os_client_config.config.CONFIG_FILES)
        self.assertIsInstance(inv.clouds, list)
        self.assertEqual(1, len(inv.clouds))
        self.assertFalse(mock_config.return_value.get_all_clouds.called)
        mock_config.return_value.get_one_cloud.assert_called_once_with(
            'supercloud')
Ejemplo n.º 3
0
    def test_get_host(self, mock_cloud, mock_config):
        mock_config.return_value.get_all_clouds.return_value = [{}]

        inv = inventory.OpenStackInventory()

        server = dict(id='server_id', name='server_name')
        self.assertIsInstance(inv.clouds, list)
        self.assertEqual(1, len(inv.clouds))
        inv.clouds[0].list_servers.return_value = [server]
        inv.clouds[0].get_openstack_vars.return_value = server

        ret = inv.get_host('server_id')
        self.assertEqual(server, ret)
Ejemplo n.º 4
0
    def test_list_hosts_no_detail(self, mock_cloud, mock_config):
        mock_config.return_value.get_all_clouds.return_value = [{}]

        inv = inventory.OpenStackInventory()

        server = self.cloud._normalize_server(
            fakes.make_fake_server('1234', 'test', 'ACTIVE', addresses={}))
        self.assertIsInstance(inv.clouds, list)
        self.assertEqual(1, len(inv.clouds))
        inv.clouds[0].list_servers.return_value = [server]

        inv.list_hosts(expand=False)

        inv.clouds[0].list_servers.assert_called_once_with(detailed=False)
        self.assertFalse(inv.clouds[0].get_openstack_vars.called)
Ejemplo n.º 5
0
 def setUp(self):
     super(TestInventory, self).setUp()
     # This needs to use an admin account, otherwise a public IP
     # is not allocated from devstack.
     self.inventory = inventory.OpenStackInventory()
     self.server_name = 'test_inventory_server'
     self.nova = self.operator_cloud.nova_client
     self.flavor = pick_flavor(self.nova.flavors.list())
     if self.flavor is None:
         self.assertTrue(False, 'no sensible flavor available')
     self.image = self.pick_image()
     self.addCleanup(self._cleanup_servers)
     self.operator_cloud.create_server(
         name=self.server_name, image=self.image, flavor=self.flavor,
         wait=True, auto_ip=True)
Ejemplo n.º 6
0
    def test_list_hosts(self, mock_cloud, mock_config):
        mock_config.return_value.get_all_clouds.return_value = [{}]

        inv = inventory.OpenStackInventory()

        server = dict(id='server_id', name='server_name')
        self.assertIsInstance(inv.clouds, list)
        self.assertEqual(1, len(inv.clouds))
        inv.clouds[0].list_servers.return_value = [server]
        inv.clouds[0].get_openstack_vars.return_value = server

        ret = inv.list_hosts()

        inv.clouds[0].list_servers.assert_called_once_with(detailed=True)
        self.assertFalse(inv.clouds[0].get_openstack_vars.called)
        self.assertEqual([server], ret)
Ejemplo n.º 7
0
 def setUp(self):
     super(TestInventory, self).setUp()
     # This needs to use an admin account, otherwise a public IP
     # is not allocated from devstack.
     self.inventory = inventory.OpenStackInventory()
     self.server_name = self.getUniqueString('inventory')
     self.flavor = pick_flavor(
         self.user_cloud.list_flavors(get_extra=False))
     if self.flavor is None:
         self.assertTrue(False, 'no sensible flavor available')
     self.image = self.pick_image()
     self.addCleanup(self._cleanup_server)
     server = self.operator_cloud.create_server(name=self.server_name,
                                                image=self.image,
                                                flavor=self.flavor,
                                                wait=True,
                                                auto_ip=True)
     self.server_id = server['id']
Ejemplo n.º 8
0
    def test_list_hosts_no_detail(self, mock_cloud, mock_add, mock_config):
        mock_config.return_value.get_all_clouds.return_value = [{}]

        inv = inventory.OpenStackInventory()

        server = _utils.normalize_server(meta.obj_to_dict(
            fakes.FakeServer('1234', 'test', 'ACTIVE', addresses={})),
                                         region_name='',
                                         cloud_name='')
        self.assertIsInstance(inv.clouds, list)
        self.assertEqual(1, len(inv.clouds))
        inv.clouds[0].list_servers.return_value = [server]

        inv.list_hosts(expand=False)

        inv.clouds[0].list_servers.assert_called_once_with()
        self.assertFalse(inv.clouds[0].get_openstack_vars.called)
        mock_add.assert_called_once_with(inv.clouds[0], server)
Ejemplo n.º 9
0
 def test_get_host_no_detail(self, mock_search):
     inv = inventory.OpenStackInventory()
     inv.get_host('server_id', expand=False)
     mock_search.assert_called_once_with('server_id', None, expand=False)