def test_unplug(self, tag, vif_data, exists): instance = stubs.MockInstance() vif = copy.deepcopy(self.vif_data) self.mgr.net.device_exists.side_effect = exists self.assertEqual(None, self.vif_driver.unplug(instance, vif)) calls = [mock.call.net.device_exists('qbr0123456789a')] if exists[0]: calls[1:1] = [ mock.call.ex('brctl', 'delif', 'qbr0123456789a', 'qvb0123456789a', run_as_root=True), mock.call.ex('ip', 'link', 'set', 'qbr0123456789a', 'down', run_as_root=True), mock.call.ex('brctl', 'delbr', 'qbr0123456789a', run_as_root=True), mock.call.net.delete_ovs_vif_port('fakebr', 'qvo0123456789a') ] self.assertEqual(calls, self.mgr.method_calls)
def test_nonetype(self): instance = stubs.MockInstance() vif_data = {'type': None} self.assertRaises( exception.NovaException, self.vif_driver.plug, instance, vif_data)
def test_cleanup(self, mr): instance = stubs.MockInstance() self.assertEqual( None, self.connection.cleanup({}, instance, [], [], None, None, None)) mr.assert_called_once_with( '/fake/instances/path/fake-uuid')
def test_unplug_fail(self): instance = stubs.MockInstance() vif_data = copy.deepcopy(self.vif_data) self.mgr.net.device_exists.side_effect = ( processutils.ProcessExecutionError) self.assertEqual( None, self.vif_driver.unplug(instance, vif_data))
def test_spawn_defined(self, tag, side_effect, expected): instance = stubs.MockInstance() self.ml.container_defined.side_effect = side_effect self.assertRaises( expected, self.connection.spawn, {}, instance, {}, [], 'secret') self.ml.container_defined.called_once_with('mock_instance')
def test_configure_container_configdrive_wrong_format(self): instance = stubs.MockInstance() with mock.patch.object(container_config.CONF, 'config_drive_format', new='fake-format'): self.assertRaises( exception.InstancePowerOnFailure, self.container_config.configure_container_configdrive, {}, instance, {})
def test_rescue_defined(self): instance = stubs.MockInstance() self.ml.container_defined.return_value = True self.assertRaises(exception.InstanceExists, self.container_ops.spawn, {}, instance, {}, [], 'secret', rescue=True) self.ml.container_defined.called_once_with('fake-instance')
def test_configure_container_config(self, tag, flavor, expected): instance = stubs.MockInstance(**flavor) config = { 'raw.lxc': 'lxc.console.logfile=/fake/lxd/root/containers/' 'fake-uuid/console.log\n' } config.update(expected) self.assertEqual({'config': config}, self.container_config.configure_container_config( {}, instance))
def test_plug(self, tag, vif_data, exists): instance = stubs.MockInstance() vif_data = copy.deepcopy(self.vif_data) vif_data.update(vif_data) self.mgr.net.device_exists.side_effect = exists self.assertEqual(None, self.vif_driver.plug(instance, vif_data)) calls = [ mock.call.net.device_exists('qbr0123456789a'), mock.call.net.device_exists('qvo0123456789a') ] if not exists[0]: calls[1:1] = [ mock.call.ex('brctl', 'addbr', 'qbr0123456789a', run_as_root=True), mock.call.ex('brctl', 'setfd', 'qbr0123456789a', 0, run_as_root=True), mock.call.ex('brctl', 'stp', 'qbr0123456789a', 'off', run_as_root=True), mock.call.ex('tee', '/sys/class/net/qbr0123456789a/' 'bridge/multicast_snooping', process_input='0', run_as_root=True, check_exit_code=[0, 1]), ] if not exists[1]: calls.extend([ mock.call.net._create_veth_pair('qvb0123456789a', 'qvo0123456789a'), mock.call.ex('ip', 'link', 'set', 'qbr0123456789a', 'up', run_as_root=True), mock.call.ex('brctl', 'addif', 'qbr0123456789a', 'qvb0123456789a', run_as_root=True) ]) calls.append( mock.call.net.create_ovs_vif_port('fakebr', 'qvo0123456789a', '0123456789abcdef', '00:11:22:33:44:55', 'fake-uuid')) self.assertEqual(calls, self.mgr.method_calls)
def test_configure_container_rescuedisk(self): instance = stubs.MockInstance() self.assertEqual( { 'devices': { 'rescue': { 'path': 'mnt', 'source': '/fake/lxd/root/containers/' 'fake-uuid-backup/rootfs', 'type': 'disk' } } }, self.container_config.configure_container_rescuedisk({}, instance))
def test_configure_container_configdrive_fail_dir(self, md, mi): instance = stubs.MockInstance() injected_files = mock.Mock() self.assertRaises( AttributeError, self.container_config.configure_container_configdrive, None, instance, injected_files) md.assert_called_once_with(instance_md=mi.return_value) (md.return_value.__enter__.return_value.make_drive. assert_called_once_with('/fake/instances/path/fake-uuid/config-drive') ) mi.assert_called_once_with(instance, content=injected_files, extra_md={})
def test_get_console_output(self, me, mo): instance = stubs.MockInstance() mo.return_value.__enter__.return_value = six.BytesIO(b'fake contents') self.assertEqual(b'fake contents', self.connection.get_console_output({}, instance)) calls = [ mock.call('chown', '1234:1234', '/var/log/lxd/fake-uuid/console.log', run_as_root=True), mock.call('chmod', '755', '/fake/lxd/root/containers/fake-uuid', run_as_root=True) ] self.assertEqual(calls, me.call_args_list)
def test_spawn_new(self, tag, side_effect, mc): context = mock.Mock() instance = stubs.MockInstance() image_meta = mock.Mock() injected_files = mock.Mock() network_info = mock.Mock() block_device_info = mock.Mock() self.ml.container_defined.side_effect = [side_effect] with test.nested( mock.patch.object(self.connection.container_ops, 'spawn'), ) as ( create_container ): self.connection.spawn(context, instance, image_meta, injected_files, None, network_info, block_device_info) self.assertTrue(create_container)
def test_start_instance(self, mu, tag='', rescue=False, running=False, is_neutron=True, timeout=10, network_info=[], vifs=(), plug_side_effect=None): instance = stubs.MockInstance() container_config = mock.Mock() need_vif_plugged = True self.ml.container_running.return_value = running self.ml.container_start.return_value = (200, { 'operation': '/1.0/operations/0123456789' }) container_ops.CONF.vif_plugging_timeout = timeout mu.is_neutron.return_value = is_neutron self.mv.plug.side_effect = plug_side_effect with mock.patch.object(self.container_ops.virtapi, 'wait_for_instance_event') as mw: self.assertEqual( None, self.container_ops.start_container(container_config, instance, network_info, need_vif_plugged)) mw.assert_called_once_with( instance, [('network-vif-plugged', vif) for vif in vifs], deadline=timeout, error_callback=self.container_ops._neutron_failed_callback) self.assertEqual( [mock.call(instance, viface) for viface in network_info], self.mv.plug.call_args_list) calls = [ mock.call.container_start('fake-uuid', 5), mock.call.wait_container_operation('/1.0/operations/0123456789', 200, -1) ] self.assertEqual(calls, self.ml.method_calls[-2:])
def test_configure_container_configdrive(self, md, mi): instance = stubs.MockInstance() injected_files = mock.Mock() self.assertEqual( { 'devices': { 'configdrive': { 'path': 'mnt', 'type': 'disk', 'source': '/fake/instances/path/' 'fake-uuid/config-drive' } } }, self.container_config.configure_container_configdrive( {}, instance, injected_files)) md.assert_called_once_with(instance_md=mi.return_value) (md.return_value.__enter__.return_value.make_drive. assert_called_once_with('/fake/instances/path/fake-uuid/config-drive') ) mi.assert_called_once_with(instance, content=injected_files, extra_md={})
def test_instance_exists(self, expected, name): self.assertEqual( expected, self.connection.instance_exists(stubs.MockInstance(name=name)))