Skip to content

Commit

Permalink
pyupgrade --py36-plus as 3.6 is the minimum supported version
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Deziel <simon.deziel@canonical.com>
  • Loading branch information
simondeziel committed May 5, 2023
1 parent fe37358 commit ed4210a
Show file tree
Hide file tree
Showing 26 changed files with 81 additions and 84 deletions.
10 changes: 5 additions & 5 deletions contrib_testing/local-http-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def log(s):
now = datetime.datetime.utcnow()
print("{} - {}".format(now, s))
print(f"{now} - {s}")


def create_and_update(client):
Expand All @@ -39,11 +39,11 @@ def create_and_update(client):
["apt-get", "install", "openssh-server", "sudo", "man", "-y"],
]
for command in commands:
log("command: {}".format(command))
log(f"command: {command}")
result = base.execute(command)
log("result: {}".format(result.exit_code))
log("stdout: {}".format(result.stdout))
log("stderr: {}".format(result.stderr))
log(f"result: {result.exit_code}")
log(f"stdout: {result.stdout}")
log(f"stderr: {result.stderr}")


if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions contrib_testing/local-unix-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def log(s):
now = datetime.datetime.utcnow()
print("{} - {}".format(now, s))
print(f"{now} - {s}")


def create_and_update(client):
Expand All @@ -39,11 +39,11 @@ def create_and_update(client):
["apt-get", "install", "openssh-server", "sudo", "man", "-y"],
]
for command in commands:
log("command: {}".format(command))
log(f"command: {command}")
result = base.execute(command)
log("result: {}".format(result.exit_code))
log("stdout: {}".format(result.stdout))
log("stderr: {}".format(result.stderr))
log(f"result: {result.exit_code}")
log(f"stdout: {result.stdout}")
log(f"stderr: {result.stderr}")


if __name__ == "__main__":
Expand Down
10 changes: 5 additions & 5 deletions contrib_testing/remote-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

def log(s):
now = datetime.datetime.utcnow()
print("{} - {}".format(now, s))
print(f"{now} - {s}")


def create_and_update(client):
Expand All @@ -40,11 +40,11 @@ def create_and_update(client):
["apt-get", "install", "openssh-server", "sudo", "man", "-y"],
]
for command in commands:
log("command: {}".format(command))
log(f"command: {command}")
result = base.execute(command)
log("result: {}".format(result.exit_code))
log("stdout: {}".format(result.stdout))
log("stderr: {}".format(result.stderr))
log(f"result: {result.exit_code}")
log(f"stdout: {result.stdout}")
log(f"stderr: {result.stderr}")


if __name__ == "__main__":
Expand Down
1 change: 0 additions & 1 deletion doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Expand Down
2 changes: 1 addition & 1 deletion integration/test_cluster_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class ClusterMemberTestCase(IntegrationTestCase):
def setUp(self):
super(ClusterMemberTestCase, self).setUp()
super().setUp()

if not self.client.has_api_extension("clustering"):
self.skipTest("Required LXD API extension not available!")
Expand Down
4 changes: 2 additions & 2 deletions integration/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ class TestContainer(IntegrationTestCase):
"""Tests for Client.Container."""

def setUp(self):
super(TestContainer, self).setUp()
super().setUp()
name = self.create_container()
self.container = self.client.containers.get(name)

def tearDown(self):
super(TestContainer, self).tearDown()
super().tearDown()
self.delete_container(self.container.name)

def test_save(self):
Expand Down
4 changes: 2 additions & 2 deletions integration/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ class TestImage(IntegrationTestCase):
"""Tests for Image."""

def setUp(self):
super(TestImage, self).setUp()
super().setUp()
fingerprint, _ = self.create_image()
self.image = self.client.images.get(fingerprint)

def tearDown(self):
super(TestImage, self).tearDown()
super().tearDown()
self.delete_image(self.image.fingerprint)

def test_save(self):
Expand Down
6 changes: 3 additions & 3 deletions integration/test_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class NetworkTestCase(IntegrationTestCase):
def setUp(self):
super(NetworkTestCase, self).setUp()
super().setUp()

if not self.client.has_api_extension("network"):
self.skipTest("Required LXD API extension not available!")
Expand Down Expand Up @@ -88,12 +88,12 @@ class TestNetwork(NetworkTestCase):
"""Tests for `Network`."""

def setUp(self):
super(TestNetwork, self).setUp()
super().setUp()
name = self.create_network()
self.network = self.client.networks.get(name)

def tearDown(self):
super(TestNetwork, self).tearDown()
super().tearDown()
self.delete_network(self.network.name)

def test_save(self):
Expand Down
4 changes: 2 additions & 2 deletions integration/test_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,12 @@ class TestProfile(IntegrationTestCase):
"""Tests for `Profile`."""

def setUp(self):
super(TestProfile, self).setUp()
super().setUp()
name = self.create_profile()
self.profile = self.client.profiles.get(name)

def tearDown(self):
super(TestProfile, self).tearDown()
super().tearDown()
self.delete_profile(self.profile.name)

def test_save(self):
Expand Down
2 changes: 1 addition & 1 deletion integration/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class StorageTestCase(IntegrationTestCase):
def setUp(self):
super(StorageTestCase, self).setUp()
super().setUp()

if not self.client.has_api_extension("storage"):
self.skipTest("Required LXD API extension not available!")
Expand Down
4 changes: 2 additions & 2 deletions integration/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class IntegrationTestCase(unittest.TestCase):
"""A base test case for pylxd integration tests."""

def setUp(self):
super(IntegrationTestCase, self).setUp()
super().setUp()
self.client = Client()
self.lxd = self.client.api

Expand All @@ -34,7 +34,7 @@ def generate_object_name(self):
# Underscores are not allowed in container names.
test = self.id().split(".")[-1].replace("_", "")
rando = str(uuid.uuid1()).split("-")[-1]
return "{}-{}".format(test, rando)
return f"{test}-{rando}"

def create_container(self):
"""Create a container in lxd."""
Expand Down
4 changes: 2 additions & 2 deletions migration/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class TestContainer(IntegrationTestCase):
"""Tests for Client.Container."""

def setUp(self):
super(TestContainer, self).setUp()
super().setUp()
name = self.create_container()
self.container = self.client.containers.get(name)

def tearDown(self):
super(TestContainer, self).tearDown()
super().tearDown()
self.delete_container(self.container.name)

def test_migrate_running(self):
Expand Down
4 changes: 2 additions & 2 deletions migration/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class IntegrationTestCase(unittest.TestCase):
"""A base test case for pylxd integration tests."""

def setUp(self):
super(IntegrationTestCase, self).setUp()
super().setUp()
self.client = Client()
self.lxd = self.client.api

Expand All @@ -34,7 +34,7 @@ def generate_object_name(self):
# Underscores are not allowed in container names.
test = self.id().split(".")[-1].replace("_", "")
rando = str(uuid.uuid1()).split("-")[-1]
return "{}-{}".format(test, rando)
return f"{test}-{rando}"

def create_container(self):
"""Create a container in lxd."""
Expand Down
2 changes: 0 additions & 2 deletions pylxd/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
Expand Down
6 changes: 3 additions & 3 deletions pylxd/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def __getattr__(self, name):
if name in ("storage_pools", "virtual_machines"):
name = name.replace("_", "-")
return self.__class__(
"{}/{}".format(self._api_endpoint, name),
f"{self._api_endpoint}/{name}",
session=self.session,
timeout=self._timeout,
project=self._project,
Expand All @@ -137,7 +137,7 @@ def __getitem__(self, item):
:rtype: _APINode
"""
return self.__class__(
"{}/{}".format(self._api_endpoint, item),
f"{self._api_endpoint}/{item}",
session=self.session,
timeout=self._timeout,
project=self._project,
Expand Down Expand Up @@ -543,7 +543,7 @@ def events(self, websocket_client=None, event_types=None):
if event_types and EventType.All not in event_types:
query = parse.parse_qs(parsed.query)
query.update({"type": ",".join(t.value for t in event_types)})
resource = "{}?{}".format(resource, parse.urlencode(query))
resource = f"{resource}?{parse.urlencode(query)}"

client.resource = resource

Expand Down
8 changes: 4 additions & 4 deletions pylxd/deprecated/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ def get_ws(self, path):
if self.unix_socket:
connection_string = "ws+unix://%s" % self.unix_socket
else:
connection_string = "wss://%(host)s:%(port)s" % {
"host": self.host,
"port": self.port,
}
connection_string = "wss://{host}:{port}".format(
host=self.host,
port=self.port,
)

ws = WebSocketClient(connection_string)
ws.resource = path
Expand Down
14 changes: 7 additions & 7 deletions pylxd/deprecated/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def container_migrate(self, container):

def container_migrate_sync(self, operation_id, container_secret):
return self.connection.get_ws(
"/1.0/operations/%s/websocket?secret=%s" % (operation_id, container_secret)
"/1.0/operations/{}/websocket?secret={}".format(operation_id, container_secret)
)

def container_local_copy(self, container):
Expand All @@ -150,15 +150,15 @@ def container_local_move(self, instance, config):
# file operations
def get_container_file(self, container, filename):
return self.connection.get_raw(
"GET", "/1.0/containers/%s/files?path=%s" % (container, filename)
"GET", "/1.0/containers/{}/files?path={}".format(container, filename)
)

def put_container_file(self, container, src_file, dst_file, uid, gid, mode):
with open(src_file, "rb") as f:
data = f.read()
return self.connection.get_object(
"POST",
"/1.0/containers/%s/files?path=%s" % (container, dst_file),
"/1.0/containers/{}/files?path={}".format(container, dst_file),
body=data,
headers={"X-LXD-uid": uid, "X-LXD-gid": gid, "X-LXD-mode": mode},
)
Expand All @@ -185,7 +185,7 @@ def snapshot_list(self, container):
"GET", "/1.0/containers/%s/snapshots" % container
)
return [
snapshot.split("/1.0/containers/%s/snapshots/%s/" % (container, container))[
snapshot.split("/1.0/containers/{}/snapshots/{}/".format(container, container))[
-1
]
for snapshot in data["metadata"]
Expand All @@ -198,17 +198,17 @@ def snapshot_create(self, container, config):

def snapshot_info(self, container, snapshot):
return self.connection.get_object(
"GET", "/1.0/containers/%s/snapshots/%s" % (container, snapshot)
"GET", "/1.0/containers/{}/snapshots/{}".format(container, snapshot)
)

def snapshot_rename(self, container, snapshot, config):
return self.connection.get_object(
"POST",
"/1.0/containers/%s/snapshots/%s" % (container, snapshot),
"/1.0/containers/{}/snapshots/{}".format(container, snapshot),
json.dumps(config),
)

def snapshot_delete(self, container, snapshot):
return self.connection.get_object(
"DELETE", "/1.0/containers/%s/snapshots/%s" % (container, snapshot)
"DELETE", "/1.0/containers/{}/snapshots/{}".format(container, snapshot)
)
2 changes: 1 addition & 1 deletion pylxd/deprecated/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class ImageInvalidSize(PyLXDException):

class APIError(PyLXDException):
def __init__(self, error, status_code):
msg = "Error %s - %s." % (status_code, error)
msg = "Error {} - {}.".format(status_code, error)
super().__init__(msg)
self.status_code = status_code
self.error = error

0 comments on commit ed4210a

Please sign in to comment.