Skip to content

Commit

Permalink
make lint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrue committed Aug 2, 2022
1 parent 2c1d3de commit 4ab1c2e
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions openapi_server/denbi/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

Expand Down Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions openapi_server/denbi/ser_de.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
12 changes: 6 additions & 6 deletions openapi_server/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
26 changes: 13 additions & 13 deletions openapi_server/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@

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


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
Expand Down
6 changes: 3 additions & 3 deletions openapi_server/test/test_default_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 4ab1c2e

Please sign in to comment.