コード例 #1
0
    def test_date_creates_dates_correctly(self):
        start_str = ('<date-started unixtime="1437474661504">'
                     '2015-07-21T10:31:01Z'
                     '</date-started>')
        end_str = ('<date-ended unixtime="1437474662344">'
                   '2015-07-21T10:31:02Z'
                   '</date-ended>')

        start_tree = etree.fromstring(start_str)
        end_tree = etree.fromstring(end_str)

        start_expected = {
            'unixtime': '1437474661504',
            'time': '2015-07-21T10:31:01Z'
        }
        nt.assert_equal(
            start_expected,
            xmlp.parse(start_tree, 'attribute text',
                       self.parser.start_date_parse_table))

        end_expected = {
            'unixtime': '1437474662344',
            'time': '2015-07-21T10:31:02Z'
        }
        nt.assert_equal(
            end_expected,
            xmlp.parse(end_tree, 'attribute text',
                       self.parser.date_ended_parse_table))
コード例 #2
0
    def test_date_creates_dates_correctly(self):
        start_str = ('<date-started unixtime="1437474661504">'
                     '2015-07-21T10:31:01Z'
                     '</date-started>')
        end_str = ('<date-ended unixtime="1437474662344">'
                   '2015-07-21T10:31:02Z'
                   '</date-ended>')

        start_tree = etree.fromstring(start_str)
        end_tree = etree.fromstring(end_str)

        start_expected = {
            'unixtime': '1437474661504',
            'time': '2015-07-21T10:31:01Z'
        }
        nt.assert_equal(start_expected,
                        xmlp.parse(start_tree, 'attribute text',
                                   self.parser.start_date_parse_table))

        end_expected = {
            'unixtime': '1437474662344',
            'time': '2015-07-21T10:31:02Z'
        }
        nt.assert_equal(end_expected,
                        xmlp.parse(end_tree, 'attribute text',
                                   self.parser.date_ended_parse_table))
コード例 #3
0
    def test_composite_raises_if_xml_contains_unknown_tag(self):
        xml_str = ('<root>'
                   '<child1>Text</child1>'
                   '<child2>Text</child2>'
                   '<non-child>Text</non-child>'
                   '</root>')

        xml_tree = etree.fromstring(xml_str)
        parse_table = {
            'tag': 'root',
            'type': 'composite',
            'all': [
                {
                    'tag': 'child1',
                    'type': 'text'
                },
            ],
            'any': [
                {
                    'tag': 'child2',
                    'type': 'text'
                },
            ],
        }
        xmlp.parse(xml_tree, cb_type='composite', parse_table=parse_table)
コード例 #4
0
    def test_attribute_text_raises_if_xml_has_children(self):
        xml_str = ('<root a="v">Text'
                   '<child>Child text</child>'
                   '</root>')
        xml_tree = etree.fromstring(xml_str)

        parse_table = {'tag': 'root', 'type': 'attribute text'}
        xmlp.parse(xml_tree, cb_type='attribute text', parse_table=parse_table)
コード例 #5
0
 def test_option_creates_option_correctly(self):
     xml_str = '<option name="arg1" value="foo"/>'
     xml_tree = etree.fromstring(xml_str)
     expected = {'name': 'arg1', 'value': 'foo'}
     nt.assert_equal(
         expected,
         xmlp.parse(xml_tree, 'attribute', self.parser.option_parse_table))
コード例 #6
0
    def test_composite_renames_attribute_if_child_has_the_same_name(self):
        xml_str = ('<root child1="value">'
                   '<child1>Text</child1>'
                   '<child2>Text</child2>'
                   '</root>')
        expected = {
            'child1_attribute': 'value',
            'child1': 'Text',
            'child2': 'Text'
        }
        xml_tree = etree.fromstring(xml_str)

        parse_table = {
            'tag': 'root',
            'type': 'composite',
            'all': [
                {
                    'tag': 'child1',
                    'type': 'text'
                },
            ],
            'any': [
                {
                    'tag': 'child2',
                    'type': 'text'
                },
            ],
        }
        result = xmlp.parse(xml_tree,
                            cb_type='composite',
                            parse_table=parse_table)
        nt.assert_equal(expected, result)
コード例 #7
0
    def test_jobs_creates_multiple_jobs_correctly(self):
        multiple_jobs = path.join(config.rundeck_test_data_dir,
                                  'multiple_jobs.xml')
        with open(multiple_jobs) as jobs_fl:
            multiple_jobs = etree.fromstring(jobs_fl.read())
        expected = {
            'count': 3,
            'list': [
                {
                    'id': "3b8a86d5-4fc3-4cc1-95a2-8b51421c2069",
                    'name': 'job_with_args',
                    'group': '',
                    'project': 'API_client_development',
                    'description': ''
                },
                {
                    'id': "ea17d859-32ff-45c8-8a0d-a16ac1ea3566",
                    'name': 'long job',
                    'group': '',
                    'project': 'API_client_development',
                    'description': 'async testing'
                },
                {
                    'id': "78f491e7-714f-44c6-bddb-8b3b3a961ace",
                    'name': 'test_job_1',
                    'group': '',
                    'project': 'API_client_development',
                    'description': ''
                },
            ]
        }

        nt.assert_equal(expected, xmlp.parse(multiple_jobs, 'list',
                                             self.parser.jobs_parse_table))
コード例 #8
0
    def test_composite_renames_attribute_if_child_has_the_same_name(self):
        xml_str = (
            '<root child1="value">'
            '<child1>Text</child1>'
            '<child2>Text</child2>'
            '</root>'
        )
        expected = {
            'child1_attribute': 'value',
            'child1': 'Text',
            'child2': 'Text'
        }
        xml_tree = etree.fromstring(xml_str)

        parse_table = {
            'tag': 'root',
            'type': 'composite',
            'all': [
                {'tag': 'child1', 'type': 'text'},
            ],
            'any': [
                {'tag': 'child2', 'type': 'text'},
            ],
        }
        result = xmlp.parse(xml_tree, cb_type='composite',
                            parse_table=parse_table)
        nt.assert_equal(expected, result)
コード例 #9
0
 def test_option_creates_option_correctly(self):
     xml_str = '<option name="arg1" value="foo"/>'
     xml_tree = etree.fromstring(xml_str)
     expected = {'name': 'arg1', 'value': 'foo'}
     nt.assert_equal(expected,
                     xmlp.parse(xml_tree, 'attribute',
                                self.parser.option_parse_table))
コード例 #10
0
 def test_node_creates_node_correctly(self):
     xml_str = '<node name="localhost"/>'
     xml_tree = etree.fromstring(xml_str)
     expected = {'name': 'localhost'}
     nt.assert_equal(
         expected,
         xmlp.parse(xml_tree, 'attribute', self.parser.node_parse_table))
コード例 #11
0
 def test_nodes_create_node_list(self):
     xml_str = ('<successfulNodes><node name="localhost"/>'
                '<node name="otherhost"/></successfulNodes>')
     xml_tree = etree.fromstring(xml_str)
     expected = {'list': [{'name': 'localhost'}, {'name': 'otherhost'}]}
     nt.assert_equal(expected,
                     xmlp.parse(xml_tree, 'list',
                                self.parser.successful_nodes_parse_table))
コード例 #12
0
 def test_nodes_create_node_list(self):
     xml_str = ('<successfulNodes><node name="localhost"/>'
                '<node name="otherhost"/></successfulNodes>')
     xml_tree = etree.fromstring(xml_str)
     expected = {'list': [{'name': 'localhost'}, {'name': 'otherhost'}]}
     nt.assert_equal(
         expected,
         xmlp.parse(xml_tree, 'list',
                    self.parser.successful_nodes_parse_table))
コード例 #13
0
ファイル: endpoints.py プロジェクト: EKT/pyrundeck
    def list_jobs(self, native=True, **params):
        """Implements `list jobs`_

        .. _list jobs: http://rundeck.org/docs/api/index.html#listing-jobs
        """
        status, xml = self.get('{}/api/1/jobs'.format(self.root_url), params)
        if native:
            return status, parse(xml)
        else:
            return status, xml
コード例 #14
0
    def list_jobs(self, native=True, **params):
        """Implements `list jobs`_

        .. _list jobs: http://rundeck.org/docs/api/index.html#listing-jobs
        """
        status, xml = self.get('{}/api/1/jobs'.format(self.root_url), params)
        if native:
            return status, parse(xml)
        else:
            return status, xml
コード例 #15
0
    def test_alternative_type_raises_if_none_of_the_alternatives_parse(self):
        xml_str = ('<root foo="bar">'
                   '<tags>'
                   '<tag2 lala="test"/>'
                   '<tag2 lala="test2"/>'
                   '</tags>'
                   '</root>')

        xml_tree = etree.fromstring(xml_str)

        parse_table = {
            'tag': 'root',
            'type': 'alternatives',
            'parse tables': [
                {'type': 'text'},
                {'type': 'attribute'}
            ]
        }

        xmlp.parse(xml_tree, cb_type='alternatives', parse_table=parse_table)
コード例 #16
0
ファイル: endpoints.py プロジェクト: EKT/pyrundeck
    def import_job(self, native=True, **params):
        """Implements `import job`_

        .. _import job: http://rundeck.org/docs/api/index.html#importing-jobs
        """
        status, xml = self.post('{}/api/1/jobs/import'.format(self.root_url),
                                params)
        if native:
            return status, parse(xml)
        else:
            return status, xml
コード例 #17
0
    def import_job(self, native=True, **params):
        """Implements `import job`_

        .. _import job: http://rundeck.org/docs/api/index.html#importing-jobs
        """
        status, xml = self.post('{}/api/1/jobs/import'.format(self.root_url),
                                params)
        if native:
            return status, parse(xml)
        else:
            return status, xml
コード例 #18
0
    def test_alternative_type_raises_if_none_of_the_alternatives_parse(self):
        xml_str = ('<root foo="bar">'
                   '<tags>'
                   '<tag2 lala="test"/>'
                   '<tag2 lala="test2"/>'
                   '</tags>'
                   '</root>')

        xml_tree = etree.fromstring(xml_str)

        parse_table = {
            'tag': 'root',
            'type': 'alternatives',
            'parse tables': [{
                'type': 'text'
            }, {
                'type': 'attribute'
            }]
        }

        xmlp.parse(xml_tree, cb_type='alternatives', parse_table=parse_table)
コード例 #19
0
ファイル: endpoints.py プロジェクト: EKT/pyrundeck
    def system_info(self, native=True, **params):
        """Implements `System Info`_

        .. _System Info: http://rundeck.org/docs/api/index.html#system-info
        """
        status, xml = self.get('{}/api/1/system/info'.format(self.root_url),
                               params)

        if native:
            return status, parse(xml)
        else:
            return status, xml
コード例 #20
0
    def system_info(self, native=True, **params):
        """Implements `System Info`_

        .. _System Info: http://rundeck.org/docs/api/index.html#system-info
        """
        status, xml = self.get('{}/api/1/system/info'.format(self.root_url),
                               params)

        if native:
            return status, parse(xml)
        else:
            return status, xml
コード例 #21
0
    def test_composite_raises_if_xml_contains_unknown_tag(self):
        xml_str = (
            '<root>'
            '<child1>Text</child1>'
            '<child2>Text</child2>'
            '<non-child>Text</non-child>'
            '</root>'
        )

        xml_tree = etree.fromstring(xml_str)
        parse_table = {
            'tag': 'root',
            'type': 'composite',
            'all': [
                {'tag': 'child1', 'type': 'text'},
            ],
            'any': [
                {'tag': 'child2', 'type': 'text'},
            ],
        }
        xmlp.parse(xml_tree, cb_type='composite', parse_table=parse_table)
コード例 #22
0
ファイル: endpoints.py プロジェクト: EKT/pyrundeck
    def bulk_job_delete(self, native=True, **params):
        """Implements `Bulk Job Delete`_

        .. _Bulk Job Delete: http://rundeck.org/docs/api/index.html#bulk-job-delete
        """

        status, xml = self.delete('{}/api/5/jobs/delete'.format(self.root_url),
                                  params)

        if native:
            return status, parse(xml)
        else:
            return status, xml
コード例 #23
0
    def running_executions(self, native=True, **params):
        """Implements `List Running Executions`_

        .. _List Running Executions: http://rundeck.org/docs/api/index.html#listing-running-executions
        """

        status, xml = self.post(
            '{}/api/1/executions/running'.format(self.root_url), params)

        if native:
            return status, parse(xml)
        else:
            return status, xml
コード例 #24
0
ファイル: endpoints.py プロジェクト: EKT/pyrundeck
    def running_executions(self, native=True, **params):
        """Implements `List Running Executions`_

        .. _List Running Executions: http://rundeck.org/docs/api/index.html#listing-running-executions
        """

        status, xml = self.post('{}/api/1/executions/running'.format(self.root_url),
                                params)

        if native:
            return status, parse(xml)
        else:
            return status, xml
コード例 #25
0
    def bulk_job_delete(self, native=True, **params):
        """Implements `Bulk Job Delete`_

        .. _Bulk Job Delete: http://rundeck.org/docs/api/index.html#bulk-job-delete
        """

        status, xml = self.delete('{}/api/5/jobs/delete'.format(self.root_url),
                                  params)

        if native:
            return status, parse(xml)
        else:
            return status, xml
コード例 #26
0
 def test_jobs_raises_if_count_neq_jobs_len(self):
     xml_str = ('<jobs count="5">'
                '<job id="3b8a86d5-4fc3-4cc1-95a2-8b51421c2069">'
                '<name>job_with_args</name>'
                '<group/>'
                '<project>API_client_development</project>'
                '<description/>'
                '</job>'
                '<job id="ea17d859-32ff-45c8-8a0d-a16ac1ea3566">'
                '<name>long job</name>'
                '<group/>'
                '<project>API_client_development</project>'
                '<description>async testing</description>'
                '</job>'
                '<job id="78f491e7-714f-44c6-bddb-8b3b3a961ace">'
                '<name>test_job_1</name>'
                '<group/>'
                '<project>API_client_development</project>'
                '<description/>'
                '</job>'
                '</jobs>')
     xml_tree = etree.fromstring(xml_str)
     xmlp.parse(xml_tree, 'list', self.parser.jobs_parse_table)
コード例 #27
0
 def test_options_creates_option_list_correctly(self):
     xml_str = ('<options>'
                '<option name="arg1" value="foo"/>'
                '<option name="arg2" value="bar"/>'
                '</options>')
     xml_tree = etree.fromstring(xml_str)
     expected = {
         'list': [
             {'name': 'arg1', 'value': 'foo'},
             {'name': 'arg2', 'value': 'bar'}
         ]
     }
     nt.assert_equal(expected, xmlp.parse(xml_tree, 'list',
                                          self.parser.options_parse_table))
コード例 #28
0
 def test_job_creates_single_job_correctly(self):
     single_job = path.join(config.rundeck_test_data_dir,
                            'single_job_from_response.xml')
     with open(single_job) as job_fl:
         single_job_etree = etree.fromstring(job_fl.read())
     expected = {
         'id': "ea17d859-32ff-45c8-8a0d-a16ac1ea3566",
         'name': 'long job',
         'group': '',
         'project': 'API_client_development',
         'description': 'async testing'
     }
     nt.assert_equal(expected, xmlp.parse(single_job_etree, 'composite',
                                          self.parser.job_parse_table))
コード例 #29
0
 def test_jobs_raises_if_count_neq_jobs_len(self):
     xml_str = ('<jobs count="5">'
                '<job id="3b8a86d5-4fc3-4cc1-95a2-8b51421c2069">'
                '<name>job_with_args</name>'
                '<group/>'
                '<project>API_client_development</project>'
                '<description/>'
                '</job>'
                '<job id="ea17d859-32ff-45c8-8a0d-a16ac1ea3566">'
                '<name>long job</name>'
                '<group/>'
                '<project>API_client_development</project>'
                '<description>async testing</description>'
                '</job>'
                '<job id="78f491e7-714f-44c6-bddb-8b3b3a961ace">'
                '<name>test_job_1</name>'
                '<group/>'
                '<project>API_client_development</project>'
                '<description/>'
                '</job>'
                '</jobs>')
     xml_tree = etree.fromstring(xml_str)
     xmlp.parse(xml_tree, 'list', self.parser.jobs_parse_table)
コード例 #30
0
    def export_jobs(self, native=True, **params):
        """Implements `export jobs`_

        .. _export jobs: http://rundeck.org/docs/api/index.html#exporting-jobs
        """
        status, res = self.get('{}/api/1/jobs/export'.format(self.root_url),
                               params)

        if params.get('format') == 'yaml':
            return status, yaml.load(res)
        else:
            if native:
                return status, parse(res)
            else:
                return status, res
コード例 #31
0
ファイル: endpoints.py プロジェクト: EKT/pyrundeck
    def export_jobs(self, native=True, **params):
        """Implements `export jobs`_

        .. _export jobs: http://rundeck.org/docs/api/index.html#exporting-jobs
        """
        status, res = self.get('{}/api/1/jobs/export'.format(self.root_url),
                               params)

        if params.get('format') == 'yaml':
            return status, yaml.load(res)
        else:
            if native:
                return status, parse(res)
            else:
                return status, res
コード例 #32
0
    def test_alternative_type(self):
        xml_str = ('<root foo="bar">'
                   '<tags>'
                   '<tag2 lala="test"/>'
                   '<tag2 lala="test2"/>'
                   '</tags>'
                   '</root>')

        xml_tree = etree.fromstring(xml_str)

        expected = {
            'foo': 'bar',
            'tags': {
                'list': [{
                    'lala': 'test'
                }, {
                    'lala': 'test2'
                }]
            }
        }

        actual_parse_table = {
            'type':
            'composite',
            'all': [{
                'tag': 'tags',
                'type': 'list',
                'skip count': True,
                'element parse table': {
                    'tag': 'tag2',
                    'type': 'attribute'
                }
            }]
        }

        alternative_parse_table = {'type': 'text'}

        parse_table = {
            'tag': 'root',
            'type': 'alternatives',
            'parse tables': [alternative_parse_table, actual_parse_table]
        }

        nt.assert_equal(
            expected,
            xmlp.parse(xml_tree,
                       parse_table=parse_table,
                       cb_type='alternatives'))
コード例 #33
0
 def test_job_creates_single_job_correctly(self):
     single_job = path.join(config.rundeck_test_data_dir,
                            'single_job_from_response.xml')
     with open(single_job) as job_fl:
         single_job_etree = etree.fromstring(job_fl.read())
     expected = {
         'id': "ea17d859-32ff-45c8-8a0d-a16ac1ea3566",
         'name': 'long job',
         'group': '',
         'project': 'API_client_development',
         'description': 'async testing'
     }
     nt.assert_equal(
         expected,
         xmlp.parse(single_job_etree, 'composite',
                    self.parser.job_parse_table))
コード例 #34
0
    def run_job(self, native=True, **params):
        """Implements `run job`_

        .. _run job: http://rundeck.org/docs/api/index.html#running-a-job
        """
        try:
            job_id = params.pop('id')

            status, xml = self.get(
                '{}/api/1/job/{}/run'.format(self.root_url, job_id), params)
            if native:
                return status, parse(xml)
            else:
                return status, xml
        except KeyError:
            raise RundeckException("job id is required for job execution")
コード例 #35
0
ファイル: endpoints.py プロジェクト: EKT/pyrundeck
    def run_job(self, native=True, **params):
        """Implements `run job`_

        .. _run job: http://rundeck.org/docs/api/index.html#running-a-job
        """
        try:
            job_id = params.pop('id')

            status, xml = self.get('{}/api/1/job/{}/run'
                                   .format(self.root_url, job_id), params)
            if native:
                return status, parse(xml)
            else:
                return status, xml
        except KeyError:
            raise RundeckException("job id is required for job execution")
コード例 #36
0
    def test_alternative_type(self):
        xml_str = ('<root foo="bar">'
                   '<tags>'
                   '<tag2 lala="test"/>'
                   '<tag2 lala="test2"/>'
                   '</tags>'
                   '</root>')

        xml_tree = etree.fromstring(xml_str)

        expected = {
            'foo': 'bar',
            'tags': {
                'list': [
                    {'lala': 'test'},
                    {'lala': 'test2'}
                ]
            }
        }

        actual_parse_table = {
            'type': 'composite',
            'all': [
                {
                    'tag': 'tags',
                    'type': 'list',
                    'skip count': True,
                    'element parse table':
                    {'tag': 'tag2', 'type': 'attribute'}
                }
            ]
        }

        alternative_parse_table = {
            'type': 'text'
        }

        parse_table = {
            'tag': 'root',
            'type': 'alternatives',
            'parse tables': [alternative_parse_table, actual_parse_table]
        }

        nt.assert_equal(expected, xmlp.parse(xml_tree, parse_table=parse_table,
                                             cb_type='alternatives'))
コード例 #37
0
 def test_options_creates_option_list_correctly(self):
     xml_str = ('<options>'
                '<option name="arg1" value="foo"/>'
                '<option name="arg2" value="bar"/>'
                '</options>')
     xml_tree = etree.fromstring(xml_str)
     expected = {
         'list': [{
             'name': 'arg1',
             'value': 'foo'
         }, {
             'name': 'arg2',
             'value': 'bar'
         }]
     }
     nt.assert_equal(
         expected,
         xmlp.parse(xml_tree, 'list', self.parser.options_parse_table))
コード例 #38
0
 def test_result_with_jobs(self):
     expected = {
         'apiversion': '13',
         'jobs': {
             'count':
             5,
             'list': [{
                 'description': '',
                 'group': '',
                 'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                 'name': 'job_with_args',
                 'project': 'API_client_development'
             }, {
                 'description': 'async testing',
                 'group': '',
                 'id': 'ea17d859-32ff-45c8-8a0d-a16ac1ea3566',
                 'name': 'long job',
                 'project': 'API_client_development'
             }, {
                 'description': '',
                 'group': '',
                 'id': '78f491e7-714f-44c6-bddb-8b3b3a961ace',
                 'name': 'test_job_1',
                 'project': 'API_client_development'
             }, {
                 'description': '',
                 'group': '',
                 'id': '8d5ebfc8-d69a-4808-819e-9c57b7f288d2',
                 'name': 'test_job_2',
                 'project': 'API_client_development'
             }, {
                 'description': '',
                 'group': '',
                 'id': '734f8b9c-683d-49cd-a2f2-f317696b76f8',
                 'name': 'test_job_2',
                 'project': 'API_client_development'
             }]
         },
         'success': 'true'
     }
     with open(path.join(config.rundeck_test_data_dir,
                         'jobs_result.xml')) as fl:
         xml_tree = etree.fromstring(fl.read())
         nt.assert_equal(expected, xmlp.parse(xml_tree))
コード例 #39
0
    def execution_info(self, native=True, **params):
        """Implements `execution info`_

        .. _execution info: http://rundeck.org/docs/api/index.html#execution-info
        """
        try:
            execution_id = params.pop('id')

            status, xml = self.get(
                '{}/api/1/execution/{}'.format(self.root_url, execution_id),
                params)
            if native:
                return status, parse(xml)
            else:
                return status, xml

        except KeyError:
            raise RundeckException("execution id is required for "
                                   "execution info")
コード例 #40
0
    def job_definition(self, native=True, **params):
        """Implements `Getting a Job Definition`_

        .. _Getting a Job Definition: http://rundeck.org/docs/api/index.html#getting-a-job-definition
        """
        try:
            job_id = params.pop('id')
            status, res = self.get(
                '{}/api/1/job/{}'.format(self.root_url, job_id), params)

            if params.get('format') == 'yaml':
                return status, yaml.load(res)
            else:
                if native:
                    return status, parse(res)
                else:
                    return status, res
        except KeyError:
            raise RundeckException("job id is required for job definition")
コード例 #41
0
ファイル: endpoints.py プロジェクト: EKT/pyrundeck
    def job_definition(self, native=True, **params):
        """Implements `Getting a Job Definition`_

        .. _Getting a Job Definition: http://rundeck.org/docs/api/index.html#getting-a-job-definition
        """
        try:
            job_id = params.pop('id')
            status, res = self.get('{}/api/1/job/{}'
                                   .format(self.root_url, job_id), params)

            if params.get('format') == 'yaml':
                return status, yaml.load(res)
            else:
                if native:
                    return status, parse(res)
                else:
                    return status, res
        except KeyError:
            raise RundeckException("job id is required for job definition")
コード例 #42
0
ファイル: endpoints.py プロジェクト: EKT/pyrundeck
    def job_executions_info(self, native=True, **params):
        """Implements `Job executions`_

        .. _Job executions: http://rundeck.org/docs/api/#getting-executions-for-a-job
        """

        try:
            job_id = params.pop('id')

            status, xml = self.get('{}/api/1/job/{}/executions'
                                   .format(self.root_url, job_id), params)

            if native:
                return status, parse(xml)
            else:
                return status, xml

        except KeyError:
            raise RundeckException("job id is required for job executions")
コード例 #43
0
ファイル: endpoints.py プロジェクト: EKT/pyrundeck
    def execution_info(self, native=True, **params):
        """Implements `execution info`_

        .. _execution info: http://rundeck.org/docs/api/index.html#execution-info
        """
        try:
            execution_id = params.pop('id')

            status, xml = self.get('{}/api/1/execution/{}'
                                   .format(self.root_url, execution_id),
                                   params)
            if native:
                return status, parse(xml)
            else:
                return status, xml

        except KeyError:
            raise RundeckException("execution id is required for "
                                   "execution info")
コード例 #44
0
    def job_executions_info(self, native=True, **params):
        """Implements `Job executions`_

        .. _Job executions: http://rundeck.org/docs/api/#getting-executions-for-a-job
        """

        try:
            job_id = params.pop('id')

            status, xml = self.get(
                '{}/api/1/job/{}/executions'.format(self.root_url, job_id),
                params)

            if native:
                return status, parse(xml)
            else:
                return status, xml

        except KeyError:
            raise RundeckException("job id is required for job executions")
コード例 #45
0
 def test_execution_creates_single_execution_correctly(self):
     nt.assert_equal.__self__.maxDiff = 1000
     test_data_file = path.join(config.rundeck_test_data_dir,
                                'execution.xml')
     with open(test_data_file) as ex_fl:
         xml_str = ex_fl.read()
     expected = {
         'id': '117',
         'href': 'http://192.168.50.2:4440/execution/follow/117',
         'status': 'succeeded',
         'project': 'API_client_development',
         'user': '******',
         'date-started': {
             'unixtime': '1437474661504',
             'time': '2015-07-21T10:31:01Z'
         },
         'date-ended': {
             'unixtime': '1437474662344',
             'time': '2015-07-21T10:31:02Z'
         },
         'job': {
             'id': '78f491e7-714f-44c6-bddb-8b3b3a961ace',
             'averageDuration': '2716',
             'name': 'test_job_1',
             'group': '',
             'project': 'API_client_development',
             'description': '',
         },
         'description': 'echo "Hello"',
         'argstring': '',
         'successfulNodes': {
             'list': [{
                 'name': 'localhost'
             }]
         }
     }
     xml_tree = etree.fromstring(xml_str)
     nt.assert_equal(
         expected,
         xmlp.parse(xml_tree, 'composite',
                    self.parser.execution_parse_table))
コード例 #46
0
 def test_execution_creates_single_execution_correctly(self):
     nt.assert_equal.__self__.maxDiff = 1000
     test_data_file = path.join(config.rundeck_test_data_dir,
                                'execution.xml')
     with open(test_data_file) as ex_fl:
         xml_str = ex_fl.read()
     expected = {
         'id': '117',
         'href': 'http://192.168.50.2:4440/execution/follow/117',
         'status': 'succeeded',
         'project': 'API_client_development',
         'user': '******',
         'date-started': {
             'unixtime': '1437474661504',
             'time': '2015-07-21T10:31:01Z'
         },
         'date-ended': {
             'unixtime': '1437474662344',
             'time': '2015-07-21T10:31:02Z'
         },
         'job': {
             'id': '78f491e7-714f-44c6-bddb-8b3b3a961ace',
             'averageDuration': '2716',
             'name': 'test_job_1',
             'group': '',
             'project': 'API_client_development',
             'description': '',
         },
         'description': 'echo "Hello"',
         'argstring': '',
         'successfulNodes': {
             'list': [
                 {'name': 'localhost'}
             ]
         }
     }
     xml_tree = etree.fromstring(xml_str)
     nt.assert_equal(expected,
                     xmlp.parse(xml_tree, 'composite',
                                self.parser.execution_parse_table))
コード例 #47
0
    def test_jobs_creates_multiple_jobs_correctly(self):
        multiple_jobs = path.join(config.rundeck_test_data_dir,
                                  'multiple_jobs.xml')
        with open(multiple_jobs) as jobs_fl:
            multiple_jobs = etree.fromstring(jobs_fl.read())
        expected = {
            'count':
            3,
            'list': [
                {
                    'id': "3b8a86d5-4fc3-4cc1-95a2-8b51421c2069",
                    'name': 'job_with_args',
                    'group': '',
                    'project': 'API_client_development',
                    'description': ''
                },
                {
                    'id': "ea17d859-32ff-45c8-8a0d-a16ac1ea3566",
                    'name': 'long job',
                    'group': '',
                    'project': 'API_client_development',
                    'description': 'async testing'
                },
                {
                    'id': "78f491e7-714f-44c6-bddb-8b3b3a961ace",
                    'name': 'test_job_1',
                    'group': '',
                    'project': 'API_client_development',
                    'description': ''
                },
            ]
        }

        nt.assert_equal(
            expected,
            xmlp.parse(multiple_jobs, 'list', self.parser.jobs_parse_table))
コード例 #48
0
 def test_result_with_jobs(self):
     expected = {
         'apiversion': '13',
         'jobs': {'count': 5,
                  'list': [
                      {'description': '',
                       'group': '',
                       'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                       'name': 'job_with_args',
                       'project': 'API_client_development'},
                      {'description': 'async testing',
                       'group': '',
                       'id': 'ea17d859-32ff-45c8-8a0d-a16ac1ea3566',
                       'name': 'long job',
                       'project': 'API_client_development'},
                      {'description': '',
                       'group': '',
                       'id': '78f491e7-714f-44c6-bddb-8b3b3a961ace',
                       'name': 'test_job_1',
                       'project': 'API_client_development'},
                      {'description': '',
                       'group': '',
                       'id': '8d5ebfc8-d69a-4808-819e-9c57b7f288d2',
                       'name': 'test_job_2',
                       'project': 'API_client_development'},
                      {'description': '',
                       'group': '',
                       'id': '734f8b9c-683d-49cd-a2f2-f317696b76f8',
                       'name': 'test_job_2',
                       'project': 'API_client_development'}
                  ]},
         'success': 'true'}
     with open(path.join(config.rundeck_test_data_dir,
                         'jobs_result.xml')) as fl:
         xml_tree = etree.fromstring(fl.read())
         nt.assert_equal(expected, xmlp.parse(xml_tree))
コード例 #49
0
    def test_text_raises_if_xml_has_attributes(self):
        xml_str = '<root atrribute="value"/>'
        xml_tree = etree.fromstring(xml_str)

        parse_table = {'tag': 'root', 'type': 'text'}
        xmlp.parse(xml_tree, cb_type='text', parse_table=parse_table)
コード例 #50
0
 def test_executions_raises_if_given_wrong_tag(self):
     xmlp.parse(self.bogus_xml, 'list', self.parser.executions_parse_table)
コード例 #51
0
 def test_executions_raises_if_count_ne_executions_len(self):
     with open(path.join(config.rundeck_test_data_dir,
                         'bad_executions.xml')) as fl:
         xml_tree = etree.fromstring(fl.read())
         xmlp.parse(xml_tree, 'list',
                    self.parser.executions_parse_table)
コード例 #52
0
 def test_result_with_execution(self):
     expected = {
         'success': 'true',
         'apiversion': '13',
         'executions': {
             'count': 5,
             'list': [
                 {
                     'argstring': '-arg1 foo',
                     'date-ended': {
                         'time': '2015-05-28T10:44:04Z',
                         'unixtime': '1432809844967'
                     },
                     'date-started': {
                         'time': '2015-05-28T10:44:04Z',
                         'unixtime': '1432809844290'
                     },
                     'description': 'echo $RD_OPTION_ARG1',
                     'href': 'http://192.168.50.2:4440/execution/follow/53',
                     'id': '53',
                     'job': {
                         'averageDuration': '1022',
                         'description': '',
                         'group': '',
                         'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                         'name': 'job_with_args',
                         'options': {
                             'list': [{'name': 'arg1', 'value': 'foo'}]
                         },
                         'project': 'API_client_development'
                     },
                     'project': 'API_client_development',
                     'status': 'succeeded',
                     'successfulNodes': {'list': [{'name': 'localhost'}]},
                     'user': '******'
                 },
                 {
                     'argstring': '-arg1 foo',
                     'date-ended': {
                         'time': '2015-05-28T10:43:32Z',
                         'unixtime': '1432809812305'
                     },
                     'date-started': {
                         'time': '2015-05-28T10:43:31Z',
                         'unixtime': '1432809811697'
                     },
                     'description': 'echo $RD_OPTION_ARG1',
                     'href': 'http://192.168.50.2:4440/execution/follow/52',
                     'id': '52',
                     'job': {
                         'averageDuration': '1022',
                         'description': '',
                         'group': '',
                         'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                         'name': 'job_with_args',
                         'options': {
                             'list': [{'name': 'arg1', 'value': 'foo'}]
                         },
                         'project': 'API_client_development'
                     },
                     'project': 'API_client_development',
                     'status': 'succeeded',
                     'successfulNodes': {'list': [{'name': 'localhost'}]},
                     'user': '******'
                 },
                 {
                     'argstring': '-arg1 faf',
                     'date-ended': {
                         'time': '2015-05-28T09:53:15Z',
                         'unixtime': '1432806795789'
                     },
                     'date-started': {
                         'time': '2015-05-28T09:53:15Z',
                         'unixtime': '1432806795182'
                     },
                     'description': 'echo $RD_OPTION_ARG1',
                     'href': 'http://192.168.50.2:4440/execution/follow/49',
                     'id': '49',
                     'job': {
                         'averageDuration': '1022',
                         'description': '',
                         'group': '',
                         'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                         'name': 'job_with_args',
                         'options': {
                             'list': [{'name': 'arg1', 'value': 'faf'}]
                         },
                         'project': 'API_client_development'
                     },
                     'project': 'API_client_development',
                     'status': 'succeeded',
                     'successfulNodes': {'list': [{'name': 'localhost'}]},
                     'user': '******'
                 },
                 {
                     'argstring': '-arg1 foo',
                     'date-ended': {
                         'time': '2015-05-28T09:51:49Z',
                         'unixtime': '1432806709852'
                     },
                     'date-started': {
                         'time': '2015-05-28T09:51:49Z',
                         'unixtime': '1432806709140'
                     },
                     'description': 'echo $1',
                     'href': 'http://192.168.50.2:4440/execution/follow/48',
                     'id': '48',
                     'job': {
                         'averageDuration': '1022',
                         'description': '',
                         'group': '',
                         'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                         'name': 'job_with_args',
                         'options': {
                             'list': [{'name': 'arg1', 'value': 'foo'}]
                         },
                         'project': 'API_client_development'
                     },
                     'project': 'API_client_development',
                     'status': 'succeeded',
                     'successfulNodes': {'list': [{'name': 'localhost'}]},
                     'user': '******'
                 },
                 {
                     'argstring': '-arg1 foo',
                     'date-ended': {
                         'time': '2015-05-28T09:48:01Z',
                         'unixtime': '1432806481363'
                     },
                     'date-started': {
                         'time': '2015-05-28T09:47:58Z',
                         'unixtime': '1432806478853'
                     },
                     'description': 'echo $arg1',
                     'href': 'http://192.168.50.2:4440/execution/follow/46',
                     'id': '46',
                     'job': {
                         'averageDuration': '1022',
                         'description': '',
                         'group': '',
                         'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                         'name': 'job_with_args',
                         'options': {
                             'list': [{'name': 'arg1', 'value': 'foo'}]
                         },
                         'project': 'API_client_development'
                     },
                     'project': 'API_client_development',
                     'status': 'succeeded',
                     'successfulNodes': {'list': [{'name': 'localhost'}]},
                     'user': '******'
                 }
             ]
         }
     }
     with open(path.join(config.rundeck_test_data_dir,
                         'execution_result.xml')) as fl:
         xml_tree = etree.fromstring(fl.read())
         nt.assert_equal(expected, xmlp.parse(xml_tree))
コード例 #53
0
 def test_executions_raises_if_count_ne_executions_len(self):
     with open(path.join(config.rundeck_test_data_dir,
                         'bad_executions.xml')) as fl:
         xml_tree = etree.fromstring(fl.read())
         xmlp.parse(xml_tree, 'list', self.parser.executions_parse_table)
コード例 #54
0
 def test_job_raises_if_not_job_tag(self):
     xmlp.parse(self.bogus_xml, 'composite', self.parser.job_parse_table)
コード例 #55
0
 def test_result_with_execution(self):
     expected = {
         'success': 'true',
         'apiversion': '13',
         'executions': {
             'count':
             5,
             'list': [{
                 'argstring': '-arg1 foo',
                 'date-ended': {
                     'time': '2015-05-28T10:44:04Z',
                     'unixtime': '1432809844967'
                 },
                 'date-started': {
                     'time': '2015-05-28T10:44:04Z',
                     'unixtime': '1432809844290'
                 },
                 'description': 'echo $RD_OPTION_ARG1',
                 'href': 'http://192.168.50.2:4440/execution/follow/53',
                 'id': '53',
                 'job': {
                     'averageDuration': '1022',
                     'description': '',
                     'group': '',
                     'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                     'name': 'job_with_args',
                     'options': {
                         'list': [{
                             'name': 'arg1',
                             'value': 'foo'
                         }]
                     },
                     'project': 'API_client_development'
                 },
                 'project': 'API_client_development',
                 'status': 'succeeded',
                 'successfulNodes': {
                     'list': [{
                         'name': 'localhost'
                     }]
                 },
                 'user': '******'
             }, {
                 'argstring': '-arg1 foo',
                 'date-ended': {
                     'time': '2015-05-28T10:43:32Z',
                     'unixtime': '1432809812305'
                 },
                 'date-started': {
                     'time': '2015-05-28T10:43:31Z',
                     'unixtime': '1432809811697'
                 },
                 'description': 'echo $RD_OPTION_ARG1',
                 'href': 'http://192.168.50.2:4440/execution/follow/52',
                 'id': '52',
                 'job': {
                     'averageDuration': '1022',
                     'description': '',
                     'group': '',
                     'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                     'name': 'job_with_args',
                     'options': {
                         'list': [{
                             'name': 'arg1',
                             'value': 'foo'
                         }]
                     },
                     'project': 'API_client_development'
                 },
                 'project': 'API_client_development',
                 'status': 'succeeded',
                 'successfulNodes': {
                     'list': [{
                         'name': 'localhost'
                     }]
                 },
                 'user': '******'
             }, {
                 'argstring': '-arg1 faf',
                 'date-ended': {
                     'time': '2015-05-28T09:53:15Z',
                     'unixtime': '1432806795789'
                 },
                 'date-started': {
                     'time': '2015-05-28T09:53:15Z',
                     'unixtime': '1432806795182'
                 },
                 'description': 'echo $RD_OPTION_ARG1',
                 'href': 'http://192.168.50.2:4440/execution/follow/49',
                 'id': '49',
                 'job': {
                     'averageDuration': '1022',
                     'description': '',
                     'group': '',
                     'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                     'name': 'job_with_args',
                     'options': {
                         'list': [{
                             'name': 'arg1',
                             'value': 'faf'
                         }]
                     },
                     'project': 'API_client_development'
                 },
                 'project': 'API_client_development',
                 'status': 'succeeded',
                 'successfulNodes': {
                     'list': [{
                         'name': 'localhost'
                     }]
                 },
                 'user': '******'
             }, {
                 'argstring': '-arg1 foo',
                 'date-ended': {
                     'time': '2015-05-28T09:51:49Z',
                     'unixtime': '1432806709852'
                 },
                 'date-started': {
                     'time': '2015-05-28T09:51:49Z',
                     'unixtime': '1432806709140'
                 },
                 'description': 'echo $1',
                 'href': 'http://192.168.50.2:4440/execution/follow/48',
                 'id': '48',
                 'job': {
                     'averageDuration': '1022',
                     'description': '',
                     'group': '',
                     'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                     'name': 'job_with_args',
                     'options': {
                         'list': [{
                             'name': 'arg1',
                             'value': 'foo'
                         }]
                     },
                     'project': 'API_client_development'
                 },
                 'project': 'API_client_development',
                 'status': 'succeeded',
                 'successfulNodes': {
                     'list': [{
                         'name': 'localhost'
                     }]
                 },
                 'user': '******'
             }, {
                 'argstring': '-arg1 foo',
                 'date-ended': {
                     'time': '2015-05-28T09:48:01Z',
                     'unixtime': '1432806481363'
                 },
                 'date-started': {
                     'time': '2015-05-28T09:47:58Z',
                     'unixtime': '1432806478853'
                 },
                 'description': 'echo $arg1',
                 'href': 'http://192.168.50.2:4440/execution/follow/46',
                 'id': '46',
                 'job': {
                     'averageDuration': '1022',
                     'description': '',
                     'group': '',
                     'id': '3b8a86d5-4fc3-4cc1-95a2-8b51421c2069',
                     'name': 'job_with_args',
                     'options': {
                         'list': [{
                             'name': 'arg1',
                             'value': 'foo'
                         }]
                     },
                     'project': 'API_client_development'
                 },
                 'project': 'API_client_development',
                 'status': 'succeeded',
                 'successfulNodes': {
                     'list': [{
                         'name': 'localhost'
                     }]
                 },
                 'user': '******'
             }]
         }
     }
     with open(
             path.join(config.rundeck_test_data_dir,
                       'execution_result.xml')) as fl:
         xml_tree = etree.fromstring(fl.read())
         nt.assert_equal(expected, xmlp.parse(xml_tree))
コード例 #56
0
    def test_attribute_text_raises_if_xml_has_children(self):
        xml_str = ('<root a="v">Text' '<child>Child text</child>' '</root>')
        xml_tree = etree.fromstring(xml_str)

        parse_table = {'tag': 'root', 'type': 'attribute text'}
        xmlp.parse(xml_tree, cb_type='attribute text', parse_table=parse_table)
コード例 #57
0
 def test_job_raises_if_not_job_tag(self):
     xmlp.parse(self.bogus_xml, 'composite', self.parser.job_parse_table)
コード例 #58
0
    def test_text_raises_if_xml_has_attributes(self):
        xml_str = '<root atrribute="value"/>'
        xml_tree = etree.fromstring(xml_str)

        parse_table = {'tag': 'root', 'type': 'text'}
        xmlp.parse(xml_tree, cb_type='text', parse_table=parse_table)
コード例 #59
0
    def test_attribute_raises_if_xml_has_text(self):
        xml_str = '<root a="v">Text</root>'
        xml_tree = etree.fromstring(xml_str)

        parse_table = {'tag': 'root', 'type': 'attribute'}
        xmlp.parse(xml_tree, cb_type='attribute', parse_table=parse_table)
コード例 #60
0
    def test_attribute_raises_if_xml_has_text(self):
        xml_str = '<root a="v">Text</root>'
        xml_tree = etree.fromstring(xml_str)

        parse_table = {'tag': 'root', 'type': 'attribute'}
        xmlp.parse(xml_tree, cb_type='attribute', parse_table=parse_table)