Skip to content

Commit

Permalink
Fix black format issues
Browse files Browse the repository at this point in the history
Signed-off-by: Urvashi Mohnani <[email protected]>
  • Loading branch information
umohnani8 committed Feb 20, 2024
1 parent 3def3a9 commit f79ce6e
Show file tree
Hide file tree
Showing 12 changed files with 191 additions and 151 deletions.
42 changes: 23 additions & 19 deletions podman/domain/containers_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,20 +385,22 @@ def _render_payload(kwargs: MutableMapping[str, Any]) -> Dict[str, Any]:
del args[key]

# These keywords are not supported for various reasons.
unsupported_keys = set(args.keys()).intersection((
"blkio_weight",
"blkio_weight_device", # FIXME In addition to device Major/Minor include path
"device_cgroup_rules", # FIXME Where to map for Podman API?
"device_read_bps", # FIXME In addition to device Major/Minor include path
"device_read_iops", # FIXME In addition to device Major/Minor include path
"device_requests", # FIXME In addition to device Major/Minor include path
"device_write_bps", # FIXME In addition to device Major/Minor include path
"device_write_iops", # FIXME In addition to device Major/Minor include path
"domainname",
"network_disabled", # FIXME Where to map for Podman API?
"storage_opt", # FIXME Where to map for Podman API?
"tmpfs", # FIXME Where to map for Podman API?
))
unsupported_keys = set(args.keys()).intersection(
(
"blkio_weight",
"blkio_weight_device", # FIXME In addition to device Major/Minor include path
"device_cgroup_rules", # FIXME Where to map for Podman API?
"device_read_bps", # FIXME In addition to device Major/Minor include path
"device_read_iops", # FIXME In addition to device Major/Minor include path
"device_requests", # FIXME In addition to device Major/Minor include path
"device_write_bps", # FIXME In addition to device Major/Minor include path
"device_write_iops", # FIXME In addition to device Major/Minor include path
"domainname",
"network_disabled", # FIXME Where to map for Podman API?
"storage_opt", # FIXME Where to map for Podman API?
"tmpfs", # FIXME Where to map for Podman API?
)
)
if len(unsupported_keys) > 0:
raise TypeError(
f"""Keyword(s) '{" ,".join(unsupported_keys)}' are"""
Expand Down Expand Up @@ -657,11 +659,13 @@ def parse_host_port(_container_port, _protocol, _host):
}

for item in args.pop("ulimits", []):
params["r_limits"].append({
"type": item["Name"],
"hard": item["Hard"],
"soft": item["Soft"],
})
params["r_limits"].append(
{
"type": item["Name"],
"hard": item["Hard"],
"soft": item["Soft"],
}
)

for item in args.pop("volumes", {}).items():
key, value = item
Expand Down
10 changes: 6 additions & 4 deletions podman/domain/images_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ def prune(
error.append(element["Err"])
else:
reclaimed += element["Size"]
deleted.append({
"Deleted": element["Id"],
"Untagged": "",
})
deleted.append(
{
"Deleted": element["Id"],
"Untagged": "",
}
)
if len(error) > 0:
raise APIError(response.url, response=response, explanation="; ".join(error))

Expand Down
26 changes: 15 additions & 11 deletions podman/domain/ipam.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ def __init__(
aux_addresses: Ignored.
"""
super().__init__()
self.update({
"AuxiliaryAddresses": aux_addresses,
"Gateway": gateway,
"IPRange": iprange,
"Subnet": subnet,
})
self.update(
{
"AuxiliaryAddresses": aux_addresses,
"Gateway": gateway,
"IPRange": iprange,
"Subnet": subnet,
}
)


class IPAMConfig(dict):
Expand All @@ -50,8 +52,10 @@ def __init__(
options: Options to provide to the Network driver.
"""
super().__init__()
self.update({
"Config": pool_configs or [],
"Driver": driver,
"Options": options or {},
})
self.update(
{
"Config": pool_configs or [],
"Driver": driver,
"Options": options or {},
}
)
22 changes: 13 additions & 9 deletions podman/tests/integration/test_container_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,12 @@ def test_container_ports(self):
self.containers.append(container)

self.assertTrue(
all([
x in port_test['expected_output']
for x in container.attrs.get('HostConfig', {}).get('PortBindings')
])
all(
[
x in port_test['expected_output']
for x in container.attrs.get('HostConfig', {}).get('PortBindings')
]
)
)

def test_container_healthchecks(self):
Expand Down Expand Up @@ -241,11 +243,13 @@ def test_container_devices(self):
for device in devices:
path_on_host, path_in_container = device.split(':', 1)
self.assertTrue(
any([
c.get('PathOnHost') == path_on_host
and c.get('PathInContainer') == path_in_container
for c in container_devices
])
any(
[
c.get('PathOnHost') == path_on_host
and c.get('PathInContainer') == path_in_container
for c in container_devices
]
)
)

with self.subTest("Check devices in running container object"):
Expand Down
14 changes: 8 additions & 6 deletions podman/tests/integration/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,14 @@ def __init__(
if os.environ.get("container") == "oci":
self.cmd.append("--storage-driver=vfs")

self.cmd.extend([
"system",
"service",
f"--time={timeout}",
socket_uri,
])
self.cmd.extend(
[
"system",
"service",
f"--time={timeout}",
socket_uri,
]
)

process = subprocess.run(
[podman_exe, "--version"], check=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
Expand Down
54 changes: 30 additions & 24 deletions podman/tests/unit/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,18 @@ def test_start(self, mock):

@requests_mock.Mocker()
def test_stats(self, mock):
stream = [{
"Error": None,
"Stats": [{
"ContainerId": "87e1325c82424e49a00abdd4de08009eb76c7de8d228426a9b8af9318ced5ecd",
"Name": "evil_ptolemy",
"CPU": 1000.0,
}],
}]
stream = [
{
"Error": None,
"Stats": [
{
"ContainerId": "87e1325c82424e49a00abdd4de08009eb76c7de8d228426a9b8af9318ced5ecd",
"Name": "evil_ptolemy",
"CPU": 1000.0,
}
],
}
]
buffer = io.StringIO()
for entry in stream:
buffer.write(json.JSONEncoder().encode(entry))
Expand Down Expand Up @@ -395,23 +399,25 @@ def test_top(self, mock):

@requests_mock.Mocker()
def test_top_with_streaming(self, mock):
stream = [{
"Processes": [
[
'jhonce',
'2417',
'2274',
'0',
'Mar01',
'?',
'00:00:01',
'/usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "/usr/bin/gnome-session"',
stream = [
{
"Processes": [
[
'jhonce',
'2417',
'2274',
'0',
'Mar01',
'?',
'00:00:01',
'/usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "/usr/bin/gnome-session"',
],
['jhonce', '5544', '3522', '0', 'Mar01', 'pts/1', '00:00:02', '-bash'],
['jhonce', '6140', '3522', '0', 'Mar01', 'pts/2', '00:00:00', '-bash'],
],
['jhonce', '5544', '3522', '0', 'Mar01', 'pts/1', '00:00:02', '-bash'],
['jhonce', '6140', '3522', '0', 'Mar01', 'pts/2', '00:00:00', '-bash'],
],
"Titles": ["UID", "PID", "PPID", "C", "STIME", "TTY", "TIME CMD"],
}]
"Titles": ["UID", "PID", "PPID", "C", "STIME", "TTY", "TIME CMD"],
}
]

buffer = io.StringIO()
for entry in stream:
Expand Down
30 changes: 16 additions & 14 deletions podman/tests/unit/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ def tearDown(self) -> None:

@requests_mock.Mocker()
def test_list(self, mock):
stream = [{
"Type": "pod",
"Action": "create",
"Actor": {
"ID": "",
"Attributes": {
"image": "",
"name": "",
"containerExitCode": 0,
stream = [
{
"Type": "pod",
"Action": "create",
"Actor": {
"ID": "",
"Attributes": {
"image": "",
"name": "",
"containerExitCode": 0,
},
},
},
"Scope": "local",
"Time": 1615845480,
"TimeNano": 1615845480,
}]
"Scope": "local",
"Time": 1615845480,
"TimeNano": 1615845480,
}
]
buffer = io.StringIO()
for item in stream:
buffer.write(json.JSONEncoder().encode(item))
Expand Down
18 changes: 10 additions & 8 deletions podman/tests/unit/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ def test_history(self, mock):
adapter = mock.get(
tests.LIBPOD_URL
+ "/images/326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab/history",
json=[{
"Id": "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab",
"Comment": "",
"Created": 1614208404,
"CreatedBy": "2021-02-24T23:13:24+00:00",
"Tags": ["latest"],
"Size": 1024,
}],
json=[
{
"Id": "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab",
"Comment": "",
"Created": 1614208404,
"CreatedBy": "2021-02-24T23:13:24+00:00",
"Tags": ["latest"],
"Size": 1024,
}
],
)
image = Image(attrs=FIRST_IMAGE, client=self.client.api)

Expand Down
20 changes: 12 additions & 8 deletions podman/tests/unit/test_imagesmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ def test_prune(self, mock):
"""Unit test Images prune()."""
mock.post(
tests.LIBPOD_URL + "/images/prune",
json=[{
"Id": "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab",
"Err": None,
"Size": 1024,
}],
json=[
{
"Id": "326dd9d7add24646a325e8eaa82125294027db2332e49c5828d96312c5d773ab",
"Err": None,
"Size": 1024,
}
],
)

results = self.client.images.prune()
Expand Down Expand Up @@ -210,9 +212,11 @@ def test_prune_failure(self, mock):
"""Unit test to report error carried in response body."""
mock.post(
tests.LIBPOD_URL + "/images/prune",
json=[{
"Err": "Test prune failure in response body.",
}],
json=[
{
"Err": "Test prune failure in response body.",
}
],
)

with self.assertRaises(APIError) as e:
Expand Down
18 changes: 10 additions & 8 deletions podman/tests/unit/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@
"driver": "bridge",
"network_interface": "libpod_veth0",
"created": "2022-01-28T09:18:37.491308364-07:00",
"subnets": [{
"subnet": "10.11.12.0/24",
"gateway": "10.11.12.1",
"lease_range": {
"start_ip": "10.11.12.1",
"end_ip": "10.11.12.63",
},
}],
"subnets": [
{
"subnet": "10.11.12.0/24",
"gateway": "10.11.12.1",
"lease_range": {
"start_ip": "10.11.12.1",
"end_ip": "10.11.12.63",
},
}
],
"ipv6_enabled": False,
"internal": False,
"dns_enabled": False,
Expand Down
Loading

0 comments on commit f79ce6e

Please sign in to comment.