def get_port_tag_dict(port_name):
    ovsdb_json = json.loads(base.execute("sudo", "ovsdb-client dump Port name tag -f json"))

    for data in ovsdb_json["data"]:
        name, tag = data
        if name == port_name:
            return tag
示例#2
0
 def _openstack_noauth(self, cmd, *args, **kwargs):
     exe = os.path.join(cfg.CONF.tatuclient.directory, 'openstack')
     options = build_option_string({
         '--os-url': cfg.CONF.identity.override_endpoint,
         '--os-token': cfg.CONF.identity.override_token,
     })
     cmd = options + " " + cmd
     return base.execute(exe, cmd, *args, **kwargs)
示例#3
0
def get_port_tag_dict(port_name):
    ovsdb_json = json.loads(
        base.execute("sudo", "ovsdb-client dump Port name tag -f json"))

    for data in ovsdb_json['data']:
        name, tag = data
        if name == port_name:
            return tag
 def _openstack_noauth(self, cmd, *args, **kwargs):
     exe = os.path.join(cfg.CONF.designateclient.directory, 'openstack')
     options = build_option_string({
         '--os-url': cfg.CONF.identity.override_endpoint,
         '--os-token': cfg.CONF.identity.override_token,
     })
     cmd = options + " " + cmd
     return base.execute(exe, cmd, *args, **kwargs)
示例#5
0
    def aodh(self, action, flags='', params='',
             fail_ok=False, merge_stderr=False):
        creds = ("--os-auth-plugin aodh-noauth "
                 "--user-id %s --project-id %s "
                 "--aodh-endpoint %s") % (self.user_id,
                                          self.project_id,
                                          self.endpoint)

        flags = creds + ' ' + flags

        return base.execute("aodh", action, flags, params, fail_ok,
                            merge_stderr, self.cli_dir)
示例#6
0
    def mistral(self, action, flags='', params='', fail_ok=False):
        """Executes Mistral command."""
        mistral_url_op = "--os-mistral-url %s" % self._mistral_url

        if 'WITHOUT_AUTH' in os.environ:
            return base.execute('mistral %s' % mistral_url_op,
                                action,
                                flags,
                                params,
                                fail_ok,
                                merge_stderr=False,
                                cli_dir='')
        else:
            return self.clients.cmd_with_auth('mistral %s' % mistral_url_op,
                                              action, flags, params, fail_ok)
示例#7
0
    def aodh(self,
             action,
             flags='',
             params='',
             fail_ok=False,
             merge_stderr=False):
        creds = ("--os-auth-plugin aodh-noauth "
                 "--user-id %s --project-id %s "
                 "--aodh-endpoint %s") % (self.user_id, self.project_id,
                                          self.endpoint)

        flags = creds + ' ' + flags

        return base.execute("aodh", action, flags, params, fail_ok,
                            merge_stderr, self.cli_dir)
示例#8
0
 def test_execute_failure(self, mock_popen):
     mock_popen.return_value.returncode = 1
     mock_popen.return_value.communicate.return_value = ("No such option --foobar", "")
     result = cli_base.execute("/bin/ls", action="tempest.lib", flags="--foobar", merge_stderr=True, fail_ok=True)
     args, kwargs = mock_popen.call_args
     # Check the merge_stderr
     self.assertEqual(subprocess.STDOUT, kwargs["stderr"])
     # Check action and flags are passed
     args = args[0]
     # We just tests that all pieces are passed through, we cannot make
     # assumptions about the order
     self.assertIn("/bin/ls", args)
     self.assertIn("--foobar", args)
     self.assertIn("tempest.lib", args)
     # The result is mocked - checking that the mock was invoked correctly
     self.assertIsInstance(result, str)
     self.assertIn("--foobar", result)
示例#9
0
 def test_execute_success(self, mock_popen):
     mock_popen.return_value.returncode = 0
     mock_popen.return_value.communicate.return_value = ("__init__.py", "")
     result = cli_base.execute("/bin/ls", action="tempest", flags="-l -a")
     args, kwargs = mock_popen.call_args
     # Check merge_stderr == False
     self.assertEqual(subprocess.PIPE, kwargs["stderr"])
     # Check action and flags are passed
     args = args[0]
     # We just tests that all pieces are passed through, we cannot make
     # assumptions about the order
     self.assertIn("/bin/ls", args)
     self.assertIn("-l", args)
     self.assertIn("-a", args)
     self.assertIn("tempest", args)
     # The result is mocked - checking that the mock was invoked correctly
     self.assertIsInstance(result, str)
     self.assertIn("__init__.py", result)
示例#10
0
 def test_execute_success(self, mock_popen):
     mock_popen.return_value.returncode = 0
     mock_popen.return_value.communicate.return_value = ("__init__.py", "")
     result = cli_base.execute("/bin/ls", action="tempest", flags="-l -a")
     args, kwargs = mock_popen.call_args
     # Check merge_stderr == False
     self.assertEqual(subprocess.PIPE, kwargs['stderr'])
     # Check action and flags are passed
     args = args[0]
     # We just tests that all pieces are passed through, we cannot make
     # assumptions about the order
     self.assertIn("/bin/ls", args)
     self.assertIn("-l", args)
     self.assertIn("-a", args)
     self.assertIn("tempest", args)
     # The result is mocked - checking that the mock was invoked correctly
     self.assertIsInstance(result, str)
     self.assertIn("__init__.py", result)
示例#11
0
    def _cmd_no_auth(self, cmd, action, flags='', params=''):
        """Execute given command with noauth attributes.

        :param cmd: command to be executed
        :type cmd: string
        :param action: command on cli to run
        :type action: string
        :param flags: optional cli flags to use
        :type flags: string
        :param params: optional positional args to use
        :type params: string
        """
        flags = ('--os_auth_token %(token)s --ironic_url %(url)s %(flags)s'
                 %
                 {'token': self.os_auth_token,
                  'url': self.ironic_url,
                  'flags': flags})
        return base.execute(cmd, action, flags, params,
                            cli_dir=self.client.cli_dir)
示例#12
0
    def _cmd_no_auth(self, cmd, action, flags='', params=''):
        """Execute given command with noauth attributes.

        :param cmd: command to be executed
        :type cmd: string
        :param action: command on cli to run
        :type action: string
        :param flags: optional cli flags to use
        :type flags: string
        :param params: optional positional args to use
        :type params: string
        """
        flags = ('--os_auth_token %(token)s --ironic_url %(url)s %(flags)s'
                 %
                 {'token': self.os_auth_token,
                  'url': self.ironic_url,
                  'flags': flags})
        return base.execute(cmd, action, flags, params,
                            cli_dir=self.client.cli_dir)
示例#13
0
 def test_execute_failure(self, mock_popen):
     mock_popen.return_value.returncode = 1
     mock_popen.return_value.communicate.return_value = (
         "No such option --foobar", "")
     result = cli_base.execute("/bin/ls",
                               action="tempest.lib",
                               flags="--foobar",
                               merge_stderr=True,
                               fail_ok=True)
     args, kwargs = mock_popen.call_args
     # Check the merge_stderr
     self.assertEqual(subprocess.STDOUT, kwargs['stderr'])
     # Check action and flags are passed
     args = args[0]
     # We just tests that all pieces are passed through, we cannot make
     # assumptions about the order
     self.assertIn("/bin/ls", args)
     self.assertIn("--foobar", args)
     self.assertIn("tempest.lib", args)
     # The result is mocked - checking that the mock was invoked correctly
     self.assertIsInstance(result, str)
     self.assertIn("--foobar", result)
示例#14
0
    def mistral(self, action, flags='', params='', fail_ok=False):
        """Executes Mistral command."""
        mistral_url_op = "--os-mistral-url %s" % self._mistral_url

        if 'WITHOUT_AUTH' in os.environ:
            return base.execute(
                'mistral %s' % mistral_url_op,
                action,
                flags,
                params,
                fail_ok,
                merge_stderr=False,
                cli_dir=''
            )
        else:
            return self.clients.cmd_with_auth(
                'mistral %s' % mistral_url_op,
                action,
                flags,
                params,
                fail_ok
            )
示例#15
0
 def test_execute_with_prefix(self):
     result = cli_base.execute("env", action="",
                               prefix="env NEW_VAR=1")
     self.assertIsInstance(result, str)
     self.assertIn("NEW_VAR=1", result)
示例#16
0
 def test_execute_with_prefix(self):
     result = cli_base.execute("env", action="", prefix="env NEW_VAR=1")
     self.assertIsInstance(result, str)
     self.assertIn("NEW_VAR=1", result)
示例#17
0
 def test_execute_success(self):
     result = cli_base.execute("/bin/ls", action="tempest",
                               flags="-l -a")
     self.assertIsInstance(result, str)
     self.assertIn("__init__.py", result)
示例#18
0
 def test_execute_failure(self):
     result = cli_base.execute("/bin/ls", action="tempest.lib",
                               flags="--foobar", merge_stderr=True,
                               fail_ok=True)
     self.assertIsInstance(result, str)
     self.assertIn("--foobar", result)