Exemplo n.º 1
0
    def test_post_lgjson(self):

        c = RestClient("localhost", lgweb_port, timeout=10)

        # new graphs cannot currently be added
        form_data = {
            "lg_name": "new.graph",
            "lg_content": '{"id": 1, "name": "example"}',
            "rmode": "1",
        }
        self.assertRaises(RestClientException, c._post_form, "/jsonbody", form_data)

        # Replace the contents of an existing one
        # (but replace it back with original after the test)
        original_fname = os.path.join(lg_dir, "logical_graphs", "chiles_simple.graph")
        copy_fname = tempfile.mktemp()
        shutil.copy(original_fname, copy_fname)

        try:
            form_data["lg_name"] = "logical_graphs/chiles_simple.graph"
            c._post_form("/jsonbody", form_data)
            new = c._get_json("/jsonbody?lg_name=logical_graphs/chiles_simple.graph")
            self.assertIsNotNone(new)
            self.assertIn("id", new)
            self.assertIn("name", new)
            self.assertEqual(1, new["id"])
            self.assertEqual("example", new["name"])
            self.assertEqual("1", new["reprodata"]["rmode"])
        finally:
            shutil.move(copy_fname, original_fname)
Exemplo n.º 2
0
    def test_loop_pgt_post(self):

        c = RestClient("localhost", lgweb_port, timeout=10)

        # an API call with an empty form should cause an error
        self.assertRaises(RestClientException, c._POST, "/gen_pgt")

        # new logical graph JSON
        with open(
            os.path.join(lg_dir, "logical_graphs", "testLoop.graph"), "rb"
        ) as infile:
            json_data = infile.read()

        # add 'correct' data to the form
        form_data = {
            "algo": "metis",
            "lg_name": "metis.graph",
            "json_data": json_data,
            "num_islands": 0,
            "num_par": 1,
            "par_label": "Partition",
            "max_load_imb": 100,
            "max_cpu": 8,
        }

        # POST form to /gen_pgt
        try:
            content = urllib.parse.urlencode(form_data)
            c._POST(
                "/gen_pgt", content, content_type="application/x-www-form-urlencoded"
            )
        except RestClientException as e:
            self.fail(e)
Exemplo n.º 3
0
    def test_post_lgjson(self):

        c = RestClient('localhost', lgweb_port, 10)

        # new graphs cannot currently be added
        form_data = {
            'lg_name': 'new.json',
            'lg_content': '{"id": 1, "name": "example"}'
        }
        self.assertRaises(RestClientException, c._post_form, '/jsonbody',
                          form_data)

        # Replace the contents of an existing one
        # (but replace it back with original after the test)
        original_fname = os.path.join(lg_dir, 'logical_graphs',
                                      'chiles_simple.json')
        copy_fname = tempfile.mktemp()
        shutil.copy(original_fname, copy_fname)

        try:
            form_data['lg_name'] = 'logical_graphs/chiles_simple.json'
            c._post_form('/jsonbody', form_data)
            new = c._get_json(
                '/jsonbody?lg_name=logical_graphs/chiles_simple.json')
            self.assertIsNotNone(new)
            self.assertIn('id', new)
            self.assertIn('name', new)
            self.assertEqual(1, new['id'])
            self.assertEqual('example', new['name'])
        finally:
            shutil.move(copy_fname, original_fname)
Exemplo n.º 4
0
    def test_get_pgt_post(self):

        c = RestClient('localhost', lgweb_port, 10)

        # an API call with an empty form should cause an error
        self.assertRaises(RestClientException, c._POST, '/gen_pgt')

        # new logical graph JSON
        with open('test/dropmake/logical_graphs/test-20190830-110556.graph',
                  'rb') as infile:
            json_data = infile.read()

        # add 'correct' data to the form
        form_data = {
            'algo': 'metis',
            'lg_name': 'metis.graph',
            'json_data': json_data,
            'num_islands': 0,
            'num_par': 1,
            'par_label': 'Partition',
            'max_load_imb': 100,
            'max_cpu': 8
        }

        # POST form to /gen_pgt
        try:
            content = urllib.urlencode(form_data)
            c._POST('/gen_pgt',
                    content,
                    content_type='application/x-www-form-urlencoded')
        except RestClientException as e:
            self.fail(e)
Exemplo n.º 5
0
    def test_get_lgjson(self):

        c = RestClient('localhost', lgweb_port, 10)

        # a specific one
        lg = c._get_json('/jsonbody?lg_name=logical_graphs/chiles_simple.json')
        self.assertIsNotNone(lg)

        # by default the first one found by the lg_web should be returned
        lg = c._get_json('/jsonbody')
        self.assertIsNotNone(lg)

        # doesn't exist
        self.assertRaises(RestClientException, c._get_json, '/jsonbody?lg_name=doesnt_exist.json')
Exemplo n.º 6
0
 def start_nodes(self):
     if not self._k8s_access:
         raise RuntimeError("Cannot access k8s")
     ips = [x["svc"] for x in self._pod_details.values()]
     ips.remove(self._pod_details["master"]["svc"])
     for ip in ips:
         client = RestClient(
             ip, self._value_data["service"]["daemon"]["port"], timeout=30
         )
         time.sleep(5)
         logger.debug(f"Starting node on {ip}")
         # node_ips = ['127.0.0.1'] + [x['ip'] for x in self._pod_details.values()]
         node_ips = [x["ip"] for x in self._pod_details.values()]
         # data = json.dumps({'nodes': ['127.0.0.1']}).encode('utf-8')
         data = json.dumps({"nodes": node_ips}).encode("utf-8")
         client._POST(
             "/managers/master/start", content=data, content_type="application/json"
         ).read()
Exemplo n.º 7
0
    def test_gen_pgt(self):

        c = RestClient('localhost', lgweb_port, 10)

        # doesn't exist!
        self.assertRaises(RestClientException, c._GET,
                          '/gen_pgt?lg_name=doesnt_exist.json&num_par=5&algo=metis&min_goal=0&ptype=0&max_load_imb=100')
        # unknown algorithm
        self.assertRaises(RestClientException, c._GET,
                          '/gen_pgt?lg_name=logical_graphs/chiles_simple.json&num_par=5&algo=noidea')
        # this should work now
        self._generate_pgt(c)
Exemplo n.º 8
0
    def test_load_lgeditor(self):

        c = RestClient('localhost', lgweb_port, 10)

        # doesn't exist
        self.assertRaises(RestClientException, c._get_json, '/lg_editor?lg_name=unknown.json')
        # Defaults to first LG
        c._GET('/lg_editor')
        # also fine, LG exists
        c._GET('/lg_editor?lg_name=logical_graphs/chiles_simple.json')
Exemplo n.º 9
0
    def test_get_pgtjson(self):

        c = RestClient('localhost', lgweb_port, 10)
        c._GET(
            '/gen_pgt?lg_name=logical_graphs/chiles_simple.json&num_par=5&algo=metis&min_goal=0&ptype=0&max_load_imb=100')

        # doesn't exist
        self.assertRaises(RestClientException, c._get_json, '/pgt_jsonbody?pgt_name=unknown.json')
        # good!
        c._get_json('/pgt_jsonbody?pgt_name=logical_graphs/chiles_simple1_pgt.json')
Exemplo n.º 10
0
    def test_pg_viewer(self):

        c = RestClient('localhost', lgweb_port, 10)
        self._generate_pgt(c)

        # doesn't exist
        self.assertRaises(RestClientException, c._GET, '/pg_viewer?pgt_view_name=unknown.json')
        # Defaults to first PGT
        c._GET('/pg_viewer')
        # also fine, PGT exists
        c._GET('/pg_viewer?pgt_view_name=logical_graphs/chiles_simple1_pgt.json')
Exemplo n.º 11
0
    def _test_pgt_action(self, path, unknown_fails):

        c = RestClient('localhost', lgweb_port, 10)
        self._generate_pgt(c)

        # doesn't exist
        if unknown_fails:
            self.assertRaises(RestClientException, c._GET, '/' + path + '?pgt_id=unknown.json')
        else:
            c._GET('/' + path + '?pgt_id=unknown.json')

        # exists
        c._GET('/' + path + '?pgt_id=logical_graphs/chiles_simple1_pgt.json')
Exemplo n.º 12
0
    def _test_pgt_action(self, path, unknown_fails):

        c = RestClient("localhost", lgweb_port, timeout=10)
        self._generate_pgt(c)

        # doesn't exist
        if unknown_fails:
            self.assertRaises(
                RestClientException, c._GET, "/" + path + "?pgt_id=unknown.json"
            )
        else:
            c._GET("/" + path + "?pgt_id=unknown.json")

        # exists
        c._GET("/" + path + "?pgt_id=logical_graphs/chiles_simple1_pgt.graph")
Exemplo n.º 13
0
 def start_manager(self, manager_node):
     if not self._k8s_access:
         raise RuntimeError("Cannot access k8s")
     self._submission_endpoint = self._pod_details[manager_node]["svc"]
     client = RestClient(
         self._submission_endpoint,
         self._value_data["service"]["daemon"]["port"],
         timeout=30,
     )
     node_ips = [x["ip"] for x in self._pod_details.values()]
     print(node_ips)
     data = json.dumps({"nodes": node_ips}).encode("utf-8")
     time.sleep(5)
     logger.debug(f"Starting manager on {self._submission_endpoint}")
     client._POST(
         "/managers/island/start", content=data, content_type="application/json"
     ).read()
     client._POST(
         "/managers/master/start", content=data, content_type="application/json"
     ).read()
Exemplo n.º 14
0
 def test_index(self):
     # Just check that the HTML pages load properly
     with RestClient(hostname, constants.NODE_DEFAULT_REST_PORT, 10) as c:
         c._GET('/')
         c._GET('/session')