Skip to content

Commit

Permalink
fix missing schema declaration for network.type (KeyError)
Browse files Browse the repository at this point in the history
Signed-off-by: scicco <zendar79@gmail.com>
  • Loading branch information
scicco committed Aug 25, 2022
1 parent 640fc7d commit 25bd224
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions scompose/config/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def validate_config(filepath):
"properties": {
"allocate_ip": {"type": "boolean"},
"enable": {"type": "boolean"},
"type": {"type": "string"},
# --network-args
"args": string_list,
},
Expand Down
12 changes: 9 additions & 3 deletions scompose/project/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,11 @@ def set_network(self, params):
# if not specified, set the default value for the property
for key in ["enable", "allocate_ip"]:
self.network[key] = self.network.get(key, True)

fakeroot = "--fakeroot" in self.start_opts or "-f" in self.start_opts
default_network_value = "fakeroot" if fakeroot else "bridge"

self.network["type"] = self.network.get("type", default_network_value if self.network["enable"] is True else "none")

def set_ports(self, params):
"""
Expand Down Expand Up @@ -240,7 +245,7 @@ def _get_network_commands(self, ip_address=None, network_type=None):
# network_type is "bridge" by default when network.enable is True
ports += ["--network", network_type]

if network_type is None and (not self.sudo and not fakeroot):
if network_type is None:# and (not self.sudo and not fakeroot):
ports += ["--network", "none"]

for pair in self.ports:
Expand Down Expand Up @@ -609,8 +614,9 @@ def create(self, ip_address=None, sudo=False, writable_tmpfs=False):
# Network configuration + Ports
if self.network["enable"]:
# if network.enable is true a --network must be always added
# using bridge as default
network_type = self.network["type"] or "bridge"
# using bridge or fakeroot as default
fakeroot = "--fakeroot" in self.start_opts or "-f" in self.start_opts
network_type = self.network["type"] or "fakeroot" if fakeroot else "bridge"
options += self._get_network_commands(ip_address, network_type)

# Start options
Expand Down

0 comments on commit 25bd224

Please sign in to comment.