def test_namespace_deletion(self, execute_command, unify): execute_command.side_effect = ['namespace', None] namespace = Namespace('namespace') namespace.delete() self.assertTrue(execute_command.call_count, 2) self.assertTrue(call('ip netns list') in execute_command.mock_calls) self.assertTrue(call('ip netns del namespace') in execute_command.mock_calls)
def test_namespace_existence(self, execute_command, unify): execute_command.side_effect = ['namespace'] namespace = Namespace('namespace') result = namespace.exists() self.assertTrue(result) unify.assert_called_once_with() execute_command.assert_called_once_with('ip netns list')
def test_namespace_discovery(self, execute_command, unify): execute_command.return_value = self.ip_netns_list_output default_namespace = Namespace('') first_namespace = Namespace('first_namespace') second_namespace = Namespace('second_namespace') namespaces = Namespace.discover() self.assertEqual(len(namespaces), 3) self.assertTrue(default_namespace in namespaces) self.assertTrue(first_namespace in namespaces) self.assertTrue(second_namespace in namespaces)
def step_impl(context): namespace = Namespace('') try: namespace.create() except Exception as e: context.exception = e
def step_impl(context, namespace_name): namespace = Namespace(namespace_name) assert not namespace.exists()
def step_impl(context, namespace_name): namespace = Namespace(namespace_name) if namespace not in Namespace.discover(): namespace.create()
def step_impl(context): context.discovered = Namespace.discover()
def step_impl(context, namespace_name): namespace = Namespace(namespace_name) if namespace in Namespace.discover(): namespace.delete()
def step_impl(context, namespace_name): namespace = Namespace(namespace_name) try: namespace.delete() except Exception as e: context.exception = e
def test_non_existing_namespace_deletion(self, execute_command, unify): namespace = Namespace('namespace') with self.assertRaises(ObjectNotFoundException): namespace.delete() execute_command.assert_called_once_with('ip netns list')
def test_default_namespace_deletion(self, execute_command, unify): execute_command.side_effect = [''] namespace = Namespace(Namespace.DEFAULT_NAMESPACE_NAME) with self.assertRaises(ForbiddenException): namespace.delete() execute_command.assert_not_called()
def test_default_namespace_existence(self, execute_command, unify): namespace = Namespace(Namespace.DEFAULT_NAMESPACE_NAME) result = namespace.exists() self.assertTrue(result) unify.assert_called_once_with() execute_command.assert_called_once_with('ip netns list')
def test_existing_namespace_creation(self, execute_command, unify): execute_command.side_effect = ['namespace'] namespace = Namespace('namespace') with self.assertRaises(ObjectAlreadyExistsException): namespace.create() execute_command.assert_called_once_with('ip netns list')
def test_default_namespace_creation(self, execute_command, unify): namespace = Namespace(Namespace.DEFAULT_NAMESPACE_NAME) with self.assertRaises(ObjectAlreadyExistsException): namespace.create() execute_command.assert_not_called()
def test_namespace_creation(self, execute_command, unify): namespace = Namespace('namespace') namespace.create() self.assertTrue(execute_command.call_count, 2) self.assertTrue(call('ip netns list') in execute_command.mock_calls) self.assertTrue(call('ip netns add namespace') in execute_command.mock_calls)
def test_init(self, name, is_default, is_external): ns = Namespace(name) self.assertEqual(ns.name, name) self.assertEqual(len(ns.devices), 0) self.assertEqual(ns.is_default(), is_default) self.assertEqual(ns.is_external(), is_external)
def test_non_existing_namespace_existence(self, execute_command, unify): namespace = Namespace('namespace') result = namespace.exists() self.assertFalse(result) unify.assert_called_once_with() execute_command.assert_called_once_with('ip netns list')