X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=integration-tests%2Ftest_vimconn_gcp.py;h=ea9783bc46b6c1b2d4ff867d8d1981cf9f815da5;hb=e5d7842d49b1c9cfdabca8e9d0fa3963030412f3;hp=aa4e240db776254f4690fe39fb31bef9d9a9901c;hpb=71e66118a83d01540dbd66a7e3c15af68a53f3ca;p=osm%2FRO.git diff --git a/integration-tests/test_vimconn_gcp.py b/integration-tests/test_vimconn_gcp.py index aa4e240d..ea9783bc 100644 --- a/integration-tests/test_vimconn_gcp.py +++ b/integration-tests/test_vimconn_gcp.py @@ -24,21 +24,20 @@ This module contains unit tests for the OpenStack VIM connector Run this directly with python2 or python3. """ -import logging +from datetime import datetime import json +import logging from osm_rovim_gcp.vimconn_gcp import vimconnector -from datetime import datetime - __author__ = "Sergio G.R." __date__ = "$05-nov-2021 12:00:00$" -class TestGCPOperations(): +class TestGCPOperations: gcp_conn = None - time_id = datetime.today().strftime('%Y%m%d%H%M%S') + time_id = datetime.today().strftime("%Y%m%d%H%M%S") vim_id = "gcp-test-" + time_id vim_name = vim_id vm_name = "gcp-test-vm-" + time_id @@ -57,7 +56,7 @@ class TestGCPOperations(): credentials_file, image_id, image_connector_id, - flavor_id + flavor_id, ): self.config["project_name"] = project_name self.config["region_name"] = region_name @@ -66,7 +65,8 @@ class TestGCPOperations(): self.config["credentials"] = json.load(file) except ValueError: raise Exception( - "Not possible to read credentials JSON file %s", self.config["credentials"] + "Not possible to read credentials JSON file %s", + self.config["credentials"], ) self.image_id = image_id self.image_connector_id = image_connector_id @@ -87,8 +87,12 @@ class TestGCPOperations(): ) def test_networks(self): - net_id_1 = self.gcp_conn.new_network(self.net_name, None, {"subnet_address": "10.0.0.0/25"}) - net_id_2 = self.gcp_conn.new_network(self.net_name, None, {"subnet_address": "10.9.0.0/25"}) + net_id_1 = self.gcp_conn.new_network( + self.net_name, None, {"subnet_address": "10.0.0.0/25"} + ) + net_id_2 = self.gcp_conn.new_network( + self.net_name, None, {"subnet_address": "10.9.0.0/25"} + ) _ = self.gcp_conn.delete_network(net_id_1[0]) _ = self.gcp_conn.delete_network(net_id_2[0]) @@ -105,8 +109,12 @@ class TestGCPOperations(): _ = self.gcp_conn.delete_vminstance(vm_id_1[0]) def test_vminstances_2_nets(self): - net_id_1 = self.gcp_conn.new_network(self.net_name, None, {"subnet_address": "10.0.0.0/25"}) - net_id_2 = self.gcp_conn.new_network(self.net_name, None, {"subnet_address": "10.9.0.0/25"}) + net_id_1 = self.gcp_conn.new_network( + self.net_name, None, {"subnet_address": "10.0.0.0/25"} + ) + net_id_2 = self.gcp_conn.new_network( + self.net_name, None, {"subnet_address": "10.9.0.0/25"} + ) vm_id_1 = self.gcp_conn.new_vminstance( name=self.vm_name, @@ -114,7 +122,10 @@ class TestGCPOperations(): start=True, image_id=self.image_id, flavor_id=self.flavor_id, - net_list=[{"net_id": net_id_1[0], "use": "mgmt"}, {"net_id": net_id_2[0], "use": "internal"}], + net_list=[ + {"net_id": net_id_1[0], "use": "mgmt"}, + {"net_id": net_id_2[0], "use": "internal"}, + ], cloud_config=self.cloud_config, ) _ = self.gcp_conn.delete_vminstance(vm_id_1[0]) @@ -122,7 +133,6 @@ class TestGCPOperations(): _ = self.gcp_conn.delete_network(net_id_1[0]) _ = self.gcp_conn.delete_network(net_id_2[0]) - def test_vminstances_image_connector_id(self): image_id = self.gcp_conn.get_image_list({"name": self.image_connector_id}) vm_id_1 = self.gcp_conn.new_vminstance( @@ -138,7 +148,12 @@ class TestGCPOperations(): def test_vminstances_flavor(self): machine_type = self.gcp_conn.get_flavor_id_from_data( - {'disk': 10, 'ram': 2048, 'vcpus': 1, 'extended': {'mempage-size': 'LARGE', 'numas': [{'threads': 1}]}} + { + "disk": 10, + "ram": 2048, + "vcpus": 1, + "extended": {"mempage-size": "LARGE", "numas": [{"threads": 1}]}, + } ) vm_id_1 = self.gcp_conn.new_vminstance( name=self.vm_name, @@ -168,7 +183,7 @@ if __name__ == "__main__": try: with open(gcp_env_file) as f: for line in f: - var, value = line.replace('\n', '').split("=") + var, value = line.replace("\n", "").split("=") if var == "GCP_PROJECT": project_name = value elif var == "GCP_REGION": @@ -182,9 +197,7 @@ if __name__ == "__main__": elif var == "GCP_FLAVOR": flavor_id = value except ValueError: - raise Exception( - "Wrong format of GCP test environment file" - ) + raise Exception("Wrong format of GCP test environment file") if ( project_name is None @@ -206,11 +219,10 @@ if __name__ == "__main__": credentials_file, image_id, image_connector_id, - flavor_id + flavor_id, ) test_gcp.test_networks() test_gcp.test_vminstances_default() test_gcp.test_vminstances_2_nets() test_gcp.test_vminstances_connector_id() test_gcp.test_vminstances_flavor() -