def test_nonetype(self): instance = stubs.MockInstance() vif_data = {'type': None} self.assertRaises( exception.NovaException, self.vif_driver.plug, instance, vif_data)
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_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_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_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_cleanup(self, mr, mu): instance = stubs.MockInstance() self.assertEqual( None, self.connection.cleanup({}, instance, [], [], None, None, None))
def test_instance_exists(self, expected, name): self.assertEqual( expected, self.connection.instance_exists(stubs.MockInstance(name=name)))