コード例 #1
0
    def test_exec_cmd_iterator(self):
        cmd = "some command"

        process_mock = self.make_process_mock()
        with mock.patch.object(subprocess, "Popen", return_value=process_mock) as popen_mock:
            for line in utils.exec_cmd_iterator(cmd):
                self.assertTrue(line.startswith("Stdout line "))

        popen_mock.assert_called_once_with(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
コード例 #2
0
    def test_exec_cmd_iterator_raises_error(self):
        cmd = 'some command'
        return_code = 1

        process_mock = self.make_process_mock(return_code=return_code)
        with mock.patch.object(subprocess, 'Popen', return_value=process_mock):
            with self.assertRaisesRegexp(
                    error.ExecutedErrorNonZeroExitCode,
                    'Shell command executed with "{0}" '
                    'exit code: {1} '.format(return_code, cmd)):
                for line in utils.exec_cmd_iterator(cmd):
                    self.assertTrue(line.startswith('Stdout line '))
コード例 #3
0
ファイル: plugins.py プロジェクト: aateem/python-fuelclient
    def version_from_file(cls, file_path):
        """Retrieves plugin version from RPM.

        :param str file_path: path to rpm file
        :returns: version of the plugin
        """
        for line in utils.exec_cmd_iterator(
                "rpm -qp --queryformat '%{{version}}' {0}".format(file_path)):
            version = line
            break

        return version
コード例 #4
0
    def version_from_file(cls, file_path):
        """Retrieves plugin version from RPM.

        :param str file_path: path to rpm file
        :returns: version of the plugin
        """
        for line in utils.exec_cmd_iterator(
                "rpm -qp --queryformat '%{{version}}' {0}".format(file_path)):
            version = line
            break

        return version
コード例 #5
0
    def test_exec_cmd_iterator(self):
        cmd = 'some command'

        process_mock = self.make_process_mock()
        with mock.patch.object(subprocess, 'Popen',
                               return_value=process_mock) as popen_mock:
            for line in utils.exec_cmd_iterator(cmd):
                self.assertTrue(line.startswith('Stdout line '))

        popen_mock.assert_called_once_with(cmd,
                                           stdout=subprocess.PIPE,
                                           stderr=subprocess.PIPE,
                                           shell=True)
コード例 #6
0
ファイル: plugins.py プロジェクト: aateem/python-fuelclient
    def name_from_file(cls, file_path):
        """Retrieves plugin name from RPM. RPM name contains
        the version of the plugin, which should be removed.

        :param str file_path: path to rpm file
        :returns: name of the plugin
        """
        for line in utils.exec_cmd_iterator(
                "rpm -qp --queryformat '%{{name}}' {0}".format(file_path)):
            name = line
            break

        return cls._remove_major_plugin_version(name)
コード例 #7
0
    def name_from_file(cls, file_path):
        """Retrieves plugin name from RPM. RPM name contains
        the version of the plugin, which should be removed.

        :param str file_path: path to rpm file
        :returns: name of the plugin
        """
        for line in utils.exec_cmd_iterator(
                "rpm -qp --queryformat '%{{name}}' {0}".format(file_path)):
            name = line
            break

        return cls._remove_major_plugin_version(name)