Exemplo n.º 1
0
 def test_run_namespace(self):
     base = ip_lib.SubProcessBase('sudo', 'ns')
     base._run([], 'link', ('list', ))
     self.execute.assert_called_once_with(
         ['ip', 'netns', 'exec', 'ns', 'ip', 'link', 'list'],
         root_helper='sudo',
         log_fail_as_error=True)
Exemplo n.º 2
0
 def test_as_root_namespace(self):
     base = ip_lib.SubProcessBase(namespace='ns')
     base._as_root([], 'link', ('list', ))
     self.execute.assert_called_once_with(
         ['ip', 'netns', 'exec', 'ns', 'ip', 'link', 'list'],
         run_as_root=True,
         log_fail_as_error=True)
Exemplo n.º 3
0
 def test_enforce_root_helper_with_root_helper_supplied(self):
     base = ip_lib.SubProcessBase('sudo')
     try:
         base.enforce_root_helper()
     except exceptions.SudoRequired:
         self.fail('enforce_root_helper should not raise SudoRequired '
                   'when a root_helper is supplied.')
Exemplo n.º 4
0
 def test_enforce_root_helper_with_no_root_helper_but_root(self):
     base = ip_lib.SubProcessBase()
     with mock.patch.object(os, 'geteuid', return_value=0):
         try:
             base.enforce_root_helper()
         except exceptions.SudoRequired:
             self.fail('enforce_root_helper should not require a root '
                       'helper when run as root.')
 def test_namespace_doest_not_exist(self):
     retval = '\n'.join(NETNS_SAMPLE)
     # need another instance to avoid mocking
     netns_cmd = ip_lib.IpNetnsCommand(ip_lib.SubProcessBase())
     with mock.patch('neutron.agent.linux.utils.execute') as execute:
         execute.return_value = retval
         self.assertFalse(
             netns_cmd.exists('bbbbbbbb-1111-2222-3333-bbbbbbbbbbbb'))
         execute.assert_called_once_with(['ip', '-o', 'netns', 'list'],
                                         root_helper=None)
Exemplo n.º 6
0
 def test_namespace_doest_not_exist_no_helper(self):
     self.config(group='AGENT', use_helper_for_ns_read=False)
     retval = '\n'.join(NETNS_SAMPLE)
     # need another instance to avoid mocking
     netns_cmd = ip_lib.IpNetnsCommand(ip_lib.SubProcessBase())
     with mock.patch('neutron.agent.common.utils.execute') as execute:
         execute.return_value = retval
         self.assertFalse(
             netns_cmd.exists('bbbbbbbb-1111-2222-3333-bbbbbbbbbbbb'))
         execute.assert_called_once_with(['ip', '-o', 'netns', 'list'],
                                         run_as_root=False,
                                         log_fail_as_error=True)
 def test_as_root_no_root_helper(self):
     base = ip_lib.SubProcessBase()
     self.assertRaises(exceptions.SudoRequired,
                       base._as_root,
                       [], 'link', ('list',))
 def test_run_no_namespace(self):
     base = ip_lib.SubProcessBase('sudo')
     base._run([], 'link', ('list',))
     self.execute.assert_called_once_with(['ip', 'link', 'list'],
                                          root_helper=None)
Exemplo n.º 9
0
 def test_run_no_namespace(self):
     base = ip_lib.SubProcessBase()
     base._run([], 'link', ('list', ))
     self.execute.assert_called_once_with(['ip', 'link', 'list'],
                                          run_as_root=False,
                                          log_fail_as_error=True)
Exemplo n.º 10
0
 def test_enforce_root_helper_no_root_helper(self):
     base = ip_lib.SubProcessBase()
     not_root = 42
     with mock.patch.object(os, 'geteuid', return_value=not_root):
         self.assertRaises(exceptions.SudoRequired,
                           base.enforce_root_helper)