Example #1
0
 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)
Example #2
0
 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')
Example #3
0
    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)
Example #4
0
def step_impl(context):
    namespace = Namespace('')
    try:
        namespace.create()
    except Exception as e:
        context.exception = e
Example #5
0
def step_impl(context, namespace_name):
    namespace = Namespace(namespace_name)
    assert not namespace.exists()
Example #6
0
def step_impl(context, namespace_name):
    namespace = Namespace(namespace_name)
    if namespace not in Namespace.discover():
        namespace.create()
Example #7
0
def step_impl(context):
    context.discovered = Namespace.discover()
Example #8
0
def step_impl(context, namespace_name):
    namespace = Namespace(namespace_name)
    if namespace in Namespace.discover():
        namespace.delete()
Example #9
0
def step_impl(context, namespace_name):
    namespace = Namespace(namespace_name)
    try:
        namespace.delete()
    except Exception as e:
        context.exception = e
Example #10
0
 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')
Example #11
0
 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()
Example #12
0
 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')
Example #13
0
 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')
Example #14
0
 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()
Example #15
0
 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)
Example #16
0
 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)
Example #17
0
 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')