def test_configure_network_devices(self):
     instance = stubs._fake_instance()
     self.assertEqual(
         None,
         self.container_config.configure_network_devices({},
                                                         instance,
                                                         network_info=[]))
 def test_container_init_failure(self):
     config = mock.Mock()
     instance = stubs._fake_instance()
     host = mock.Mock()
     with contextlib.nested(
             mock.patch.object(container_client.LXDContainerClient,
                               'container_init'),
             mock.patch.object(container_client.LXDContainerClient,
                               'container_wait'),
             mock.patch.object(container_client.LXDContainerClient,
                               'container_operation_info'),
     ) as (
             container_init,
             container_wait,
             container_operation_info,
     ):
         container_init.return_value = (200, fake_api.fake_operation())
         container_operation_info.return_value = (
             200, fake_api.fake_operation_info_failed())
         self.assertRaises(exception.NovaException,
                           self.container_utils.container_init, config,
                           instance, host)
         self.assertTrue(container_init)
         self.assertTrue(container_wait)
         self.assertTrue(container_operation_info)
Пример #3
0
 def test_migrate_disk_and_power_off(self):
     instance = stubs._fake_instance()
     context = mock.Mock()
     dest = mock.Mock()
     flavor = mock.Mock()
     network_info = mock.Mock()
     container_config = mock.Mock()
     with contextlib.nested(
         mock.patch.object(container_utils.LXDContainerUtils,
                           'container_stop'),
         mock.patch.object(container_utils.LXDContainerUtils,
                           'container_migrate'),
         mock.patch.object(container_config.LXDContainerConfig,
                           'get_container_config'),
         mock.patch.object(container_client.LXDContainerClient,
                           'container_config'),
         mock.patch.object(container_config.LXDContainerConfig,
                           'configure_container_migrate'),
         mock.patch.object(container_utils.LXDContainerUtils,
                           'container_init'),
         mock.patch.object(utils, 'spawn')
     ) as (
         container_stop,
         container_migrate,
         container_migrate_config,
         get_container_config,
         container_config,
         container_init,
         spawn
     ):
         self.assertEqual({},
                          self.migrate.migrate_disk_and_power_off(
             context, instance, dest, flavor, network_info))
         container_stop.assert_called_once_with(
             instance.name, instance.host)
 def test_container_init_failure(self):
     config = mock.Mock()
     instance = stubs._fake_instance()
     host = mock.Mock()
     with contextlib.nested(
         mock.patch.object(container_client.LXDContainerClient,
                           'container_init'),
         mock.patch.object(container_client.LXDContainerClient,
                           'container_wait'),
         mock.patch.object(container_client.LXDContainerClient,
                           'container_operation_info'),
     ) as (
         container_init,
         container_wait,
         container_operation_info,
     ):
         container_init.return_value = (200, fake_api.fake_operation())
         container_operation_info.return_value = (
             200,
             fake_api.fake_operation_info_failed())
         self.assertRaises(exception.NovaException,
                           self.container_utils.container_init,
                           config, instance, host)
         self.assertTrue(container_init)
         self.assertTrue(container_wait)
         self.assertTrue(container_operation_info)
Пример #5
0
 def test_destroy(self):
     instance = stubs._fake_instance()
     context = mock.Mock()
     network_info = mock.Mock()
     with contextlib.nested(
             mock.patch.object(container_utils.LXDContainerUtils,
                               'container_stop'),
             mock.patch.object(container_utils.LXDContainerUtils,
                               'container_destroy'),
             mock.patch.object(self.connection,
                               'cleanup'),
             mock.patch.object(container_ops.LXDContainerOperations,
                               '_unplug_vifs'),
     ) as (
             container_stop,
             container_destroy,
             cleanup,
             unplug_vifs
     ):
         self.connection.destroy(context, instance, network_info)
         self.assertTrue(container_stop)
         self.assertTrue(container_destroy)
         self.assertTrue(cleanup)
         unplug_vifs.assert_called_with(instance, network_info,
                                        True)
Пример #6
0
 def test_container_power_off(self):
     instance = stubs._fake_instance()
     with contextlib.nested(
             mock.patch.object(self.connection.container_ops,
                               'power_off')) as (power_off):
         self.connection.power_off(instance)
         self.assertTrue(power_off)
Пример #7
0
 def test_finish_migration(self):
     context = mock.Mock()
     migration = {'source_compute': 'fake-source',
                  'dest_compute': 'fake-dest'}
     instance = stubs._fake_instance()
     bdevice_info = mock.Mock()
     disk_info = mock.Mock()
     network_info = mock.Mock()
     with contextlib.nested(
         mock.patch.object(container_config.LXDContainerConfig,
                           'get_container_config'),
         mock.patch.object(container_client.LXDContainerClient,
                           'client'),
         mock.patch.object(container_ops.LXDContainerOperations,
                           'start_container')
     ) as (
         get_container_config,
         container_mock_client,
         container_start
     ):
         self.assertEqual(None,
                          (self.migrate.finish_migration(context,
                                                         migration,
                                                         instance,
                                                         disk_info,
                                                         network_info,
                                                         bdevice_info)))
Пример #8
0
 def test_create_instance_initfail(self):
     instance = stubs._fake_instance()
     self.ml.container_init.side_effect = (
         lxd_exception.APIError('Fake', 500))
     self.assertEqual(None,
                      self.container_ops.create_container(
                          instance, [], [], {}, None, True))
Пример #9
0
    def test_create_container(self, tag, rescue, network_info):
        instance = stubs._fake_instance()
        injected_files = mock.Mock()
        block_device_info = mock.Mock()
        need_vif_plugged = mock.Mock()
        self.ml.container_defined.return_value = True

        with contextlib.nested(
                mock.patch.object(container_config.LXDContainerConfig,
                                  'create_container'),
                mock.patch.object(container_utils.LXDContainerUtils,
                                  'container_init'),
                mock.patch.object(self.container_ops,
                                  'start_container')
        ) as (
                create_container,
                container_init,
                start_container
        ):
            self.assertEqual(None, self.container_ops.create_container(
                instance, injected_files, network_info,
                block_device_info, rescue, need_vif_plugged))
            create_container.called_assert_called_once_with(
                instance, injected_files, block_device_info,
                rescue)
            print(container_init.method_calls)
            container_init.called_assert_called_once_with(
                container_config, instance.host)
Пример #10
0
 def test_get_info(self, tag, side_effect, expected):
     instance = stubs._fake_instance()
     with mock.patch.object(container_client.LXDContainerClient,
                            "client",
                            ) as state:
         state.return_value = side_effect
         info = self.connection.get_info(instance)
         self.assertEqual(dir(hardware.InstanceInfo(state=expected,
                                                    num_cpu=2)), dir(info))
Пример #11
0
 def test_container_power_on(self):
     context = mock.Mock()
     instance = stubs._fake_instance()
     network_info = mock.Mock()
     with contextlib.nested(
             mock.patch.object(self.connection.container_ops,
                               'power_on')) as (power_on):
         self.connection.power_on(context, instance, network_info)
         self.assertTrue(power_on)
Пример #12
0
 def test_container_power_off(self):
     instance = stubs._fake_instance()
     with contextlib.nested(
             mock.patch.object(self.connection.container_ops,
                               'power_off')
     ) as (
             power_off
     ):
         self.connection.power_off(instance)
         self.assertTrue(power_off)
Пример #13
0
 def test_container_reboot(self):
     instance = stubs._fake_instance()
     context = mock.Mock()
     network_info = mock.Mock()
     reboot_type = 'SOFT'
     with contextlib.nested(
             mock.patch.object(self.connection.container_ops,
                               'reboot')) as (reboot):
         self.connection.reboot(context, instance, network_info,
                                reboot_type)
         self.assertTrue(reboot)
Пример #14
0
 def test_get_info(self, tag, side_effect, expected):
     instance = stubs._fake_instance()
     with mock.patch.object(
             container_client.LXDContainerClient,
             "client",
     ) as state:
         state.return_value = side_effect
         info = self.connection.get_info(instance)
         self.assertEqual(
             dir(hardware.InstanceInfo(state=expected, num_cpu=2)),
             dir(info))
Пример #15
0
 def test_container_power_on(self):
     context = mock.Mock()
     instance = stubs._fake_instance()
     network_info = mock.Mock()
     with contextlib.nested(
             mock.patch.object(self.connection.container_ops,
                               'power_on')
     ) as (
             power_on
     ):
         self.connection.power_on(context, instance, network_info)
         self.assertTrue(power_on)
 def test_container_reboot(self):
     instance = stubs._fake_instance()
     with contextlib.nested(
             mock.patch.object(container_client.LXDContainerClient,
                               'container_reboot'),
             mock.patch.object(container_client.LXDContainerClient,
                               'container_wait'),
     ) as (container_reboot, container_wait):
         container_reboot.return_value = (200, fake_api.fake_operation())
         self.assertEqual(None,
                          self.container_utils.container_reboot(instance))
         self.assertTrue(container_reboot)
         self.assertTrue(container_wait)
 def test_container_pause(self):
     instance = stubs._fake_instance()
     instance_name = 'fake-uuid'
     with contextlib.nested(
             mock.patch.object(container_client.LXDContainerClient,
                               'container_pause'),
             mock.patch.object(container_client.LXDContainerClient,
                               'container_wait'),
     ) as (container_pause, container_wait):
         container_pause.return_value = (200, fake_api.fake_operation())
         self.assertEqual(None, (self.container_utils.container_pause(
             instance_name, instance)))
         self.assertTrue(container_pause)
         self.assertTrue(container_wait)
Пример #18
0
 def test_container_reboot(self):
     instance = stubs._fake_instance()
     context = mock.Mock()
     network_info = mock.Mock()
     reboot_type = 'SOFT'
     with contextlib.nested(
             mock.patch.object(self.connection.container_ops,
                               'reboot')
     ) as (
             reboot
     ):
         self.connection.reboot(context, instance,
                                network_info, reboot_type)
         self.assertTrue(reboot)
 def test_container_suspend(self):
     instance = stubs._fake_instance()
     snapshot = mock.Mock()
     with contextlib.nested(
             mock.patch.object(container_client.LXDContainerClient,
                               'container_snapshot_create'),
             mock.patch.object(container_client.LXDContainerClient,
                               'container_wait'),
     ) as (snapshot_create, container_wait):
         snapshot_create.return_value = (200, fake_api.fake_operation())
         self.assertEqual(
             None,
             (self.container_utils.container_snapshot(snapshot, instance)))
         self.assertTrue(snapshot_create)
         self.assertTrue(container_wait)
    def test_container_copy(self):
        instance = stubs._fake_instance()
        config = mock.Mock()

        with contextlib.nested(
                mock.patch.object(container_client.LXDContainerClient,
                                  'container_local_copy'),
                mock.patch.object(container_client.LXDContainerClient,
                                  'container_wait'),
        ) as (container_copy, container_wait):
            container_copy.return_value = (200, fake_api.fake_operation())
            self.assertEqual(
                None, (self.container_utils.container_copy(config, instance)))
            self.assertTrue(container_copy)
            self.assertTrue(container_wait)
 def test_fetch_imagei_fail(self, mock_execute):
     context = mock.Mock()
     instance = stubs._fake_instance()
     image_meta = {"name": "new_image", "id": "fake_image"}
     with contextlib.nested(
         mock.patch.object(container_image.LXDContainerImage, "_image_defined"),
         mock.patch.object(container_image.IMAGE_API, "download"),
         mock.patch.object(container_image.LXDContainerImage, "_get_lxd_manifest"),
         mock.patch.object(container_image.LXDContainerImage, "_image_upload"),
         mock.patch.object(container_image.LXDContainerImage, "_setup_alias"),
         mock.patch.object(os, "unlink"),
     ) as (mock_image_defined, mock_image_download, mock_image_manifest, image_upload, setup_alias, os_unlink):
         mock_image_defined.return_value = True
         self.assertEqual(None, self.container_image.setup_image(context, instance, image_meta))
         self.assertFalse(mock_image_manifest.called)
 def test_container_reboot(self):
     instance = stubs._fake_instance()
     with contextlib.nested(
         mock.patch.object(container_client.LXDContainerClient,
                           'container_reboot'),
         mock.patch.object(container_client.LXDContainerClient,
                           'container_wait'),
     ) as (
         container_reboot,
         container_wait
     ):
         container_reboot.return_value = (200, fake_api.fake_operation())
         self.assertEqual(None,
                          self.container_utils.container_reboot(instance))
         self.assertTrue(container_reboot)
         self.assertTrue(container_wait)
Пример #23
0
 def test_destroy_fail(self):
     instance = stubs._fake_instance()
     context = mock.Mock()
     network_info = mock.Mock()
     self.ml.container_destroy.side_effect = (lxd_exceptions.APIError(
         'Fake', 500))
     with contextlib.nested(
             mock.patch.object(container_utils.LXDContainerUtils,
                               'container_destroy'),
             mock.patch.object(container_utils.LXDContainerUtils,
                               'container_stop'),
             mock.patch.object(self.connection, 'cleanup'),
             mock.patch.object(container_ops.LXDContainerOperations,
                               '_unplug_vifs'),
     ) as (container_destroy, container_stop, cleanup, unplug_vifs):
         self.connection.destroy(context, instance, network_info)
 def test_fetch_image(self, mock_execute):
     context = mock.Mock()
     instance = stubs._fake_instance()
     image_meta = {"name": "new_image", "id": "fake_image"}
     with contextlib.nested(
         mock.patch.object(container_image.LXDContainerImage, "_image_defined"),
         mock.patch.object(container_image.IMAGE_API, "download"),
         mock.patch.object(container_image.LXDContainerImage, "_get_lxd_manifest"),
         mock.patch.object(container_image.LXDContainerImage, "_image_upload"),
         mock.patch.object(container_image.LXDContainerImage, "_setup_alias"),
         mock.patch.object(os, "unlink"),
     ) as (mock_image_defined, mock_image_download, mock_image_manifest, image_upload, setup_alias, os_unlink):
         mock_image_defined.return_value = False
         mock_image_manifest.return_value = "/fake/image/cache/fake_image-manifest.tar"
         self.assertEqual(None, self.container_image.setup_image(context, instance, image_meta))
         mock_execute.assert_called_once_with("xz", "-9", "/fake/image/cache/" "fake_image-manifest.tar")
 def test_container_stop(self):
     instance = stubs._fake_instance()
     instance_name = 'fake-uuid'
     with contextlib.nested(
         mock.patch.object(container_client.LXDContainerClient,
                           'container_stop'),
         mock.patch.object(container_client.LXDContainerClient,
                           'container_wait'),
     ) as (
         container_stop,
         container_wait
     ):
         container_stop.return_value = (200, fake_api.fake_operation())
         self.assertEqual(None,
                          (self.container_utils.container_stop(
                              instance_name, instance)))
         self.assertTrue(container_stop)
         self.assertTrue(container_wait)
Пример #26
0
 def test_destroy(self):
     instance = stubs._fake_instance()
     context = mock.Mock()
     network_info = mock.Mock()
     with contextlib.nested(
             mock.patch.object(container_utils.LXDContainerUtils,
                               'container_stop'),
             mock.patch.object(container_utils.LXDContainerUtils,
                               'container_destroy'),
             mock.patch.object(self.connection, 'cleanup'),
             mock.patch.object(container_ops.LXDContainerOperations,
                               '_unplug_vifs'),
     ) as (container_stop, container_destroy, cleanup, unplug_vifs):
         self.connection.destroy(context, instance, network_info)
         self.assertTrue(container_stop)
         self.assertTrue(container_destroy)
         self.assertTrue(cleanup)
         unplug_vifs.assert_called_with(instance, network_info, True)
 def test_container_suspend(self):
     instance = stubs._fake_instance()
     snapshot = mock.Mock()
     with contextlib.nested(
         mock.patch.object(container_client.LXDContainerClient,
                           'container_snapshot_create'),
         mock.patch.object(container_client.LXDContainerClient,
                           'container_wait'),
     ) as (
         snapshot_create,
         container_wait
     ):
         snapshot_create.return_value = (200, fake_api.fake_operation())
         self.assertEqual(None,
                          (self.container_utils.container_snapshot(
                              snapshot, instance)))
         self.assertTrue(snapshot_create)
         self.assertTrue(container_wait)
    def test_container_copy(self):
        instance = stubs._fake_instance()
        config = mock.Mock()

        with contextlib.nested(
            mock.patch.object(container_client.LXDContainerClient,
                              'container_local_copy'),
            mock.patch.object(container_client.LXDContainerClient,
                              'container_wait'),
        ) as (
            container_copy,
            container_wait
        ):
            container_copy.return_value = (200, fake_api.fake_operation())
            self.assertEqual(None,
                             (self.container_utils.container_copy(config,
                                                                  instance)))
            self.assertTrue(container_copy)
            self.assertTrue(container_wait)
Пример #29
0
 def test_confirm_migration(self):
     instance = stubs._fake_instance()
     migration = mock.Mock()
     network_info = mock.Mock()
     migration = {'source_compute': 'fake-source',
                  'dest_compute': 'fake-dest'}
     src = migration['source_compute']
     with contextlib.nested(
         mock.patch.object(container_client.LXDContainerClient,
                           'client'),
         mock.patch.object(container_utils.LXDContainerUtils,
                           'container_destroy')
     ) as (
         container_defined,
         container_destroy
     ):
         self.assertEqual(None,
                          (self.migrate.confirm_migration(migration,
                                                          instance,
                                                          network_info)))
         container_destroy.assert_called_once_with(instance.name,
                                                   src)
Пример #30
0
    def test_destroy_fail(self):
        instance = stubs._fake_instance()
        context = mock.Mock()
        network_info = mock.Mock()
        self.ml.container_destroy.side_effect = (
            lxd_exceptions.APIError('Fake', 500))
        with contextlib.nested(
            mock.patch.object(container_utils.LXDContainerUtils,
                              'container_destroy'),
            mock.patch.object(container_utils.LXDContainerUtils,
                              'container_stop'),
            mock.patch.object(self.connection, 'cleanup'),
            mock.patch.object(container_ops.LXDContainerOperations,
                              '_unplug_vifs'),

        ) as (
            container_destroy,
            container_stop,
            cleanup,
            unplug_vifs
        ):
            self.connection.destroy(context, instance, network_info)
 def test_configure_network_devices(self):
     instance = stubs._fake_instance()
     self.assertEqual(None,
                      self.container_config.configure_network_devices(
                          {}, instance, network_info=[]))