diff --git a/openapi_server/denbi/resources.py b/openapi_server/denbi/resources.py index 5b50653..6c0788c 100644 --- a/openapi_server/denbi/resources.py +++ b/openapi_server/denbi/resources.py @@ -41,7 +41,7 @@ def __update_aggregates__(self): for hostname in aggregate["hosts"]: # determine number of used gpus used = 0 - if hostname in self.__gpu_instances_by_host__.keys(): + if hostname in self.__gpu_instances_by_host__: for instance in self.__gpu_instances_by_host__[hostname]: used = used + int(instance["flavor"]["extra_specs"]["pci_passthrough:alias"].split(":")[1]) @@ -135,7 +135,7 @@ def __update_gpu_instances_by_host__(self): for instance in self.__osclient__.list_servers(all_projects=True): # Filter all GPU instances if "pci_passthrough:alias" in instance["flavor"]["extra_specs"].keys(): - if instance["OS-EXT-SRV-ATTR:host"] not in self.__gpu_instances_by_host__.keys(): + if instance["OS-EXT-SRV-ATTR:host"] not in self.__gpu_instances_by_host__: self.__gpu_instances_by_host__[instance["OS-EXT-SRV-ATTR:host"]] = [] self.__gpu_instances_by_host__[instance["OS-EXT-SRV-ATTR:host"]].append(instance) diff --git a/openapi_server/denbi/ser_de.py b/openapi_server/denbi/ser_de.py index 7ddeb07..cdec7cf 100644 --- a/openapi_server/denbi/ser_de.py +++ b/openapi_server/denbi/ser_de.py @@ -9,13 +9,13 @@ class JsonSerDe: See https://pymemcache.readthedocs.io/en/latest/getting_started.html#serialization """ - def serialize(self, key, value): # pylint: disable=W0613,R0201 + def serialize(self, key, value): # pylint: disable=W0613 """ Serialize value.""" if isinstance(value, str): return value.encode('utf-8'), 1 return json.dumps(value).encode('utf-8'), 2 - def deserialize(self, key, value, flags): # pylint: disable=W0613,R0201 + def deserialize(self, key, value, flags): # pylint: disable=W0613 """ Deserialize value.""" if flags == 1: return value.decode('utf-8') diff --git a/openapi_server/encoder.py b/openapi_server/encoder.py index b2d09d5..ef27b66 100644 --- a/openapi_server/encoder.py +++ b/openapi_server/encoder.py @@ -9,14 +9,14 @@ class JSONEncoder(FlaskJSONEncoder): """Auto generated by OpenAPI Generator (https://openapi-generator.tech).""" include_nulls = False - def default(self, obj): - if isinstance(obj, Model): + def default(self, o): + if isinstance(o, Model): dikt = {} - for attr, _ in six.iteritems(obj.openapi_types): - value = getattr(obj, attr) + for attr, _ in six.iteritems(o.openapi_types): + value = getattr(o, attr) if value is None and not self.include_nulls: continue - attr = obj.attribute_map[attr] + attr = o.attribute_map[attr] dikt[attr] = value return dikt - return FlaskJSONEncoder.default(self, obj) + return FlaskJSONEncoder.default(self, o) diff --git a/openapi_server/test/__init__.py b/openapi_server/test/__init__.py index 6ee296f..43ef434 100644 --- a/openapi_server/test/__init__.py +++ b/openapi_server/test/__init__.py @@ -12,21 +12,21 @@ def mock_openstack_connection(mock): mock_osclient = MagicMock() - file_handler = open(Path(__file__).parent / "list_aggregates.json") - mock_osclient.list_aggregates.return_value = json.load(file_handler) - file_handler.close() + with open(Path(__file__).parent / "list_aggregates.json", encoding='utf-8') as file_handler: + mock_osclient.list_aggregates.return_value = json.load(file_handler) + file_handler.close() - file_handler = open(Path(__file__).parent / "list_servers.json") - mock_osclient.list_servers.return_value = json.load(file_handler) - file_handler.close() + with open(Path(__file__).parent / "list_servers.json", encoding='utf-8') as file_handler: + mock_osclient.list_servers.return_value = json.load(file_handler) + file_handler.close() - file_handler = open(Path(__file__).parent / "list_hypervisors.json") - mock_osclient.list_hypervisors.return_value = json.load(file_handler) - file_handler.close() + with open(Path(__file__).parent / "list_hypervisors.json", encoding='utf-8') as file_handler: + mock_osclient.list_hypervisors.return_value = json.load(file_handler) + file_handler.close() - file_handler = open(Path(__file__).parent / "list_flavors.json") - mock_osclient.list_flavors.return_value = json.load(file_handler) - file_handler.close() + with open(Path(__file__).parent / "list_flavors.json", encoding='utf-8') as file_handler: + mock_osclient.list_flavors.return_value = json.load(file_handler) + file_handler.close() mock.return_value = mock_osclient @@ -34,7 +34,7 @@ def mock_openstack_connection(mock): class FlaskTestCase(flask_testing.TestCase): """ Subclass of flask_testing.TestCase, overwriting create_app. """ - def create_app(self): # pylint: disable=R0201 + def create_app(self): logging.getLogger('connexion.operation').setLevel('ERROR') app = connexion.App(__name__, specification_dir='../openapi/') app.app.json_encoder = JSONEncoder diff --git a/openapi_server/test/test_default_controller.py b/openapi_server/test/test_default_controller.py index b51b1c1..95902ee 100644 --- a/openapi_server/test/test_default_controller.py +++ b/openapi_server/test/test_default_controller.py @@ -17,7 +17,7 @@ class TestDefaultController(openapi_server.test.FlaskTestCase): """DefaultController integration test stubs""" - def setUp(self) -> None: # pylint: disable=C0103,R0201 + def setUp(self) -> None: # disable memcached openapi_server.controllers.enable_memcache(False) @@ -32,7 +32,7 @@ def test_gpus_flavors_flavor_openstack_id_get(self, mock) -> None: } # ask for flavor with id 'a54ed137-04fe-463f-a2b0-666079d1b2ba' response = self.client.open( - '/gpus/flavors/{flavor_openstack_id}'.format(flavor_openstack_id='a54ed137-04fe-463f-a2b0-666079d1b2ba'), + "/gpus/flavors/a54ed137-04fe-463f-a2b0-666079d1b2ba", method='GET', headers=headers) # should result in a 200 status code @@ -46,7 +46,7 @@ def test_gpus_flavors_flavor_openstack_id_get(self, mock) -> None: # ask for an unknown flavor id response = self.client.open( - '/gpus/flavors/{flavor_openstack_id}'.format(flavor_openstack_id='gibt_es_nicht'), + '/gpus/flavors/gibt_es_nicht', method='GET', headers=headers) # should result in a 404 status code