Example #1
0
    def test_post_arts(self, load_cfg_path, phout_path, meta=None):
        """
        Create new load test entrie.
        Reduce artefacts to get statistics and metadata.
        Args:
            load_cfg_path: str
            phout_path: str
            meta: dict, test entrie metadata.

        Returns:
            dict: New test entrie respresentation.

        Throws:
            LunaportClientError
        """
        resp = None
        codes_allowed = [201, ]
        url = '{}tests/'.format(self.epoint)
        files = {
            'load_cfg': load_cfg_path,
            'phout': phout_path,
        }
        try:
            resp = requests.post(url, data=meta, files=files)
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json()
Example #2
0
    def eval_post(self, test_id, oracle, result, passed):
        """ Create new test evaluation resource.
        Args:
            test_id - int, Lunaport test uniq id.
            oracle - dict, result validation rules.
            result - dict, asserts execution result.
            passed - Bool, True if test passed well.

        Returns:
            evaluation as dict, location as str.
        """
        resp = None
        codes_allowed = [
            201,
        ]
        url = '{}eval/'.format(self.epoint)
        body_json = json.dumps({
            'test_id': test_id,
            'oracle': oracle,
            'result': result,
            'passed': passed,
        })
        try:
            resp = requests.post(url,
                                 timeout=self.to,
                                 headers=self.headers,
                                 data=body_json)
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json(), resp.headers.get('location')
Example #3
0
    def eval_post(self, test_id, oracle, result, passed):
        """ Create new test evaluation resource.
        Args:
            test_id - int, Lunaport test uniq id.
            oracle - dict, result validation rules.
            result - dict, asserts execution result.
            passed - Bool, True if test passed well.

        Returns:
            evaluation as dict, location as str.
        """
        resp = None
        codes_allowed = [201, ]
        url = '{}eval/'.format(self.epoint)
        body_json = json.dumps({
            'test_id': test_id,
            'oracle': oracle,
            'result': result,
            'passed': passed,
        })
        try:
            resp = requests.post(url, timeout=self.to, headers=self.headers, data=body_json)
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json(), resp.headers.get('location')
Example #4
0
    def test_post_arts(self, load_cfg_path, phout_path, meta=None):
        """
        Create new load test entrie.
        Reduce artefacts to get statistics and metadata.
        Args:
            load_cfg_path: str
            phout_path: str
            meta: dict, test entrie metadata.

        Returns:
            dict: New test entrie respresentation.

        Throws:
            LunaportClientError
        """
        resp = None
        codes_allowed = [
            201,
        ]
        url = '{}tests/'.format(self.epoint)
        files = {
            'load_cfg': load_cfg_path,
            'phout': phout_path,
        }
        try:
            resp = requests.post(url, data=meta, files=files)
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json()
Example #5
0
    def test_post_api(self, load_cfg):
        """
        Create new load test entrie. Launch new test using load_cfg.
        Args:
            load_cfg: dict, ynadex.tank + lunaport section.

        Returns:
            dict: New test entrie respresentation.

        Throws:
            LunaportClientError
        """
        resp = None
        codes_allowed = [
            201,
        ]
        url = '{}tests/?force=true'.format(self.epoint)
        try:
            resp = requests.post(url,
                                 data=json.dumps(load_cfg),
                                 headers={'Content-type': 'application/json'})
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json()
Example #6
0
 def issue_get_names_butch(self):
     resp = None
     url = '{}issue/?names_butch=true'.format(self.epoint)
     try:
         resp = requests.get(url, timeout=self.to)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #7
0
 def line_get(self, line_id):
     resp = None
     url = "{}line/{}".format(self.epoint, line_id)
     try:
         resp = requests.get(url, timeout=self.to)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #8
0
 def dc_get(self, dc_id):
     resp = None
     url = '{}dc/{}'.format(self.epoint, dc_id)
     try:
         resp = requests.get(url, timeout=self.to)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #9
0
 def proj_get(self, proj_name):
     resp = None
     url = '{}proj/{}'.format(self.epoint, proj_name)
     try:
         resp = requests.get(url, timeout=self.to)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #10
0
 def server_get(self, fqdn):
     resp = None
     url = "{}host/{}".format(self.epoint, fqdn)
     try:
         resp = requests.get(url, timeout=self.to)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #11
0
 def proj_get_names_butch(self):
     resp = None
     url = '{}proj/?names_butch=true'.format(self.epoint)
     try:
         resp = requests.get(url, timeout=self.to)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #12
0
 def issue_get(self, issue_name):
     resp = None
     url = '{}issue/{}'.format(self.epoint, issue_name)
     try:
         resp = requests.get(url, timeout=self.to)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #13
0
 def eval_get(self, eval_id):
     resp = None
     url = '{}eval/{}'.format(self.epoint, eval_id)
     try:
         resp = requests.get(url, timeout=self.to)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #14
0
 def stat_get(self, test_id, ammo_tag='all'):
     resp = None
     url = '{}tests/{}/stat/{}'.format(self.epoint, test_id, ammo_tag)
     try:
         resp = requests.get(url, timeout=self.to)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #15
0
 def user_get(self, login):
     resp = None
     url = '{}user/{}'.format(self.epoint, login)
     try:
         resp = requests.get(url, timeout=self.to)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #16
0
 def stat_get_avail(self, test_id):
     """Get list of avaliable statistics for test.
     """
     resp = None
     url = '{}tests/{}/stat/'.format(self.epoint, test_id)
     try:
         resp = requests.get(url, timeout=self.to)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #17
0
 def notifctn_get(self, case_name):
     resp = None
     url = '{}notifications/'.format(self.epoint)
     params = {
         'case_name': case_name,
     }
     try:
         resp = requests.get(url, timeout=self.to, params=params)
         resp.raise_for_status()
         return resp.json()
     except Exception as e:
         panic(e=e, resp=resp)
Example #18
0
    def line_post(self, line):
        resp = None
        codes_allowed = [201]
        url = "{}line/".format(self.epoint)
        body_json = json.dumps(self.fillter_dct(self.line_attrs_allowed, line))
        try:
            resp = requests.post(url, timeout=self.to, headers=self.headers, data=body_json)
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json(), resp.headers.get("location")
Example #19
0
    def dc_post(self, dc):
        resp = None
        codes_allowed = [201, ]
        url = '{}dc/'.format(self.epoint)
        body_json = json.dumps(self.fillter_dct(self.dc_attrs_allowed, dc))
        try:
            resp = requests.post(url, timeout=self.to, headers=self.headers,
                                 data=body_json)
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json(), resp.headers.get('location')
Example #20
0
    def stat_post(self, test_id, ammo_tag, ver, doc):
        resp = None
        codes_allowed = [201, ]
        url = '{}tests/{}/stat/{}'.format(self.epoint, test_id, ammo_tag)
        body_json = json.dumps({
            'version': ver,
            'doc': doc,
        })
        try:
            resp = requests.post(url, timeout=self.to, headers=self.headers, data=body_json)
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json()
Example #21
0
    def proj_post(self, proj_name):
        """ All meta data will be fetched from issue tracker if possible.
        """
        resp = None
        codes_allowed = [201,]
        url = '{}proj/'.format(self.epoint)
        body_json = json.dumps({
            'name': proj_name,
        })
        try:
            resp = requests.post(url, timeout=self.to, headers=self.headers, data=body_json)
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json(), resp.headers.get('location')
Example #22
0
    def line_put(self, line):
        """ Try to update existing line entrie, insert on fail.
        Args:
            line: dict, @see line_attrs_allowed.

        Returns:
            resource representation - dict, resource location - str
        """
        resp = None
        url = "{}line/".format(self.epoint)
        body_json = json.dumps(self.fillter_dct(self.line_attrs_allowed, line))
        try:
            resp = requests.put(url, timeout=self.to, headers=self.headers, data=body_json)
            resp.raise_for_status()
        except Exception as e:
            panic(e=e, resp=resp)

        return resp.json(), resp.headers.get("location")
Example #23
0
    def case_post(self, case):
        resp = None
        codes_allowed = [
            201,
        ]
        url = '{}case/'.format(self.epoint)
        body_json = json.dumps(self.fillter_dct(self.case_attrs_allowed, case))
        try:
            resp = requests.post(url,
                                 timeout=self.to,
                                 headers=self.headers,
                                 data=body_json)
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json(), resp.headers.get('location')
Example #24
0
    def server_patch(self, fqdn, diff):
        """ Try to update existing server entrie, insert on fail.
        Args:
            fqdn: str, uniq server attribute.
            server: dict, @see server_attrs_allowed.

        Returns:
            resource representation - dict, resource location - str
        """
        resp = None
        url = "{}host/{}".format(self.epoint, fqdn)
        body_json = json.dumps(self.fillter_dct(self.server_attrs_allowed, diff))
        try:
            resp = requests.patch(url, timeout=self.to, headers=self.headers, data=body_json)
            resp.raise_for_status()
        except Exception as e:
            panic(e=e, resp=resp)

        return resp.json(), resp.headers.get("location")
Example #25
0
    def dc_put(self, dc):
        """ Try to update existing dc entrie, insert on fail.
        Args:
            dc: dict, @see dc_attrs_allowed.

        Returns:
            resource representation - dict, resource location - str
        """
        resp = None
        url = '{}dc/'.format(self.epoint)
        body_json = json.dumps(self.fillter_dct(self.dc_attrs_allowed, dc))
        try:
            resp = requests.put(url, timeout=self.to, headers=self.headers,
                                data=body_json)
            resp.raise_for_status()
        except Exception as e:
            panic(e=e, resp=resp)

        return resp.json(), resp.headers.get('location')
Example #26
0
    def test_get(self, test_id):
        """
        Fetch test entrie passing uniq identificator.
        Args:
            test_id: int

        Returns:
            dict: Test entrie respresentation.

        Throws:
            LunaportClientError
        """
        resp = None
        url = '{}tests/{}'.format(self.epoint, test_id)
        try:
            resp = requests.get(url, timeout=self.to)
            resp.raise_for_status()
            return resp.json()
        except Exception as e:
            panic(e=e, resp=resp)
Example #27
0
    def test_get(self, test_id):
        """
        Fetch test entrie passing uniq identificator.
        Args:
            test_id: int

        Returns:
            dict: Test entrie respresentation.

        Throws:
            LunaportClientError
        """
        resp = None
        url = '{}tests/{}'.format(self.epoint, test_id)
        try:
            resp = requests.get(url, timeout=self.to)
            resp.raise_for_status()
            return resp.json()
        except Exception as e:
            panic(e=e, resp=resp)
Example #28
0
    def ammo_get(self, ammo_id):
        """
        Fetch ammo entrie **not ammo file** passing uniq identificator.
        Args:
            ammo_id: int

        Returns:
            dict: Ammo entrie respresentation.

        Throws:
            LunaportClientError
        """
        resp = None
        url = '{}ammo/{}'.format(self.epoint, ammo_id)
        try:
            resp = requests.get(url, timeout=self.to)
            resp.raise_for_status()
            return resp.json()
        except Exception as e:
            panic(e=e, resp=resp)
Example #29
0
    def dc_put(self, dc):
        """ Try to update existing dc entrie, insert on fail.
        Args:
            dc: dict, @see dc_attrs_allowed.

        Returns:
            resource representation - dict, resource location - str
        """
        resp = None
        url = '{}dc/'.format(self.epoint)
        body_json = json.dumps(self.fillter_dct(self.dc_attrs_allowed, dc))
        try:
            resp = requests.put(url,
                                timeout=self.to,
                                headers=self.headers,
                                data=body_json)
            resp.raise_for_status()
        except Exception as e:
            panic(e=e, resp=resp)

        return resp.json(), resp.headers.get('location')
Example #30
0
    def case_patch(self, case_id, diff):
        """
        Patch existing case entrie.
        Args:
            case_id: int
            diff: dict

        Returns:
            dict: New case entrie respresentation.

        Throws:
            LunaportClientError
        """
        resp = None
        url = '{}case/{}'.format(self.epoint, case_id)
        try:
            resp = requests.patch(url, data=json.dumps(diff), headers=self.headers)
            resp.raise_for_status()
            return resp.json(), resp.headers.get('location')
        except Exception as e:
            panic(e=e, resp=resp)
Example #31
0
    def issue_post(self, issue_name):
        """ All meta data will be fetched from issue tracker if possible.
        """
        resp = None
        codes_allowed = [
            201,
        ]
        url = '{}issue/'.format(self.epoint)
        body_json = json.dumps({
            'name': issue_name,
        })
        try:
            resp = requests.post(url,
                                 timeout=self.to,
                                 headers=self.headers,
                                 data=body_json)
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json(), resp.headers.get('location')
Example #32
0
    def server_patch(self, fqdn, diff):
        """ Try to update existing server entrie, insert on fail.
        Args:
            fqdn: str, uniq server attribute.
            server: dict, @see server_attrs_allowed.

        Returns:
            resource representation - dict, resource location - str
        """
        resp = None
        url = '{}host/{}'.format(self.epoint, fqdn)
        body_json = json.dumps(
            self.fillter_dct(self.server_attrs_allowed, diff))
        try:
            resp = requests.patch(url,
                                  timeout=self.to,
                                  headers=self.headers,
                                  data=body_json)
            resp.raise_for_status()
        except Exception as e:
            panic(e=e, resp=resp)

        return resp.json(), resp.headers.get('location')
Example #33
0
    def test_patch(self, test_id, diff):
        """
        Patch existing test entrie.
        Args:
            test_id: int
            diff: dict

        Returns:
            dict: New test entrie respresentation.

        Throws:
            LunaportClientError
        """
        resp = None
        url = '{}tests/{}'.format(self.epoint, test_id)
        try:
            resp = requests.patch(url,
                                  data=json.dumps(diff),
                                  headers=self.headers)
            resp.raise_for_status()
            return resp.json(), resp.headers.get('location')
        except Exception as e:
            panic(e=e, resp=resp)
Example #34
0
    def test_post_api(self, load_cfg):
        """
        Create new load test entrie. Launch new test using load_cfg.
        Args:
            load_cfg: dict, ynadex.tank + lunaport section.

        Returns:
            dict: New test entrie respresentation.

        Throws:
            LunaportClientError
        """
        resp = None
        codes_allowed = [201, ]
        url = '{}tests/?force=true'.format(self.epoint)
        try:
            resp = requests.post(url, data=json.dumps(load_cfg),
                                 headers={'Content-type': 'application/json'})
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json()
Example #35
0
        Throws:
            LunaportClientError
        """
        resp = None
        codes_allowed = [
            201,
        ]
        url = '{}ammo/'.format(self.epoint)

        kw = {'data': {}}
        if files:
            # in mem file
            kw.update({'files': files})
        elif data:
            # requests_toolbelt.MultipartEncoder, if  file doesn't fetas in mem.
            kw.update({'data': data})
        else:
            raise ValueError('Malformed kw, define one of: `files` or `data`')

        kw['data'].update({'case': case, 'descr': descr})

        try:
            resp = requests.post(url, **kw)
        except Exception as e:
            panic(e=e, resp=resp)

        if resp.status_code not in codes_allowed:
            panic(resp=resp)
        return resp.json()