Skip to content

Commit 4af120d

Browse files
author
Marc Schöchlin
committed
improvements
- be more tolerant references to cloud.yaml entries - set mtu automatically if set to 0 - use directly the specified path if a file is specified Signed-off-by: Marc Schöchlin <[email protected]>
1 parent c1059a4 commit 4af120d

File tree

4 files changed

+30
-10
lines changed

4 files changed

+30
-10
lines changed

src/openstack_workload_generator/__main__.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@
4747
"adds a ssh proxy jump for the hosts without a floating ip")
4848

4949
parser.add_argument('--clouds_yaml', type=str, nargs="?",
50-
help="Generate a openstack clouds.yaml file")
50+
help="Use a specific clouds.yaml file")
5151

5252
parser.add_argument('--wait_for_machines', action="store_true",
5353
help="Wait for every machine to be created "
5454
"(normally the provisioning only waits for machines which use floating ips)")
5555

56+
parser.add_argument('--generate_clouds_yaml', type=str, nargs="?",
57+
help="Generate a openstack clouds.yaml file")
58+
59+
5660
parser.add_argument('--config', type=str,
5761
default="default.yaml",
5862
help='The config file for environment creation, define a path to the'
@@ -97,11 +101,14 @@
97101

98102

99103
def establish_connection():
100-
config = loader.OpenStackConfig()
104+
if args.clouds_yaml is None:
105+
config = loader.OpenStackConfig()
106+
else:
107+
LOGGER.info(f"Loading connection configuration from {args.clouds_yaml}")
108+
config = loader.OpenStackConfig(config_files=[args.clouds_yaml])
101109
cloud_config = config.get_one(args.os_cloud)
102110
return Connection(config=cloud_config)
103111

104-
105112
time_start = time.time()
106113

107114
Config.load_config(args.config)
@@ -132,10 +139,10 @@ def establish_connection():
132139
elif args.delete_machines:
133140
for machine_obj in workload_project.get_machines(args.delete_machines):
134141
machine_obj.delete_machine()
135-
if args.clouds_yaml:
136-
LOGGER.info(f"Creating a a clouds yaml : {args.clouds_yaml}")
142+
if args.generate_clouds_yaml:
143+
LOGGER.info(f"Creating a a clouds yaml : {args.generate_clouds_yaml}")
137144
clouds_yaml_data = {"clouds": clouds_yaml_data}
138-
with open(args.clouds_yaml, 'w') as file:
145+
with open(args.generate_clouds_yaml, 'w') as file:
139146
yaml.dump(clouds_yaml_data, file, default_flow_style=False, explicit_start=True)
140147
sys.exit(0)
141148
elif args.delete_projects:

src/openstack_workload_generator/entities/helpers.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ class Config:
2222
'admin_vm_ssh_keypair_name': 'my_ssh_public_key',
2323
'project_ipv4_subnet': '192.168.200.0/24',
2424
'public_network': "public",
25-
'network_mtu': '1500',
25+
'network_mtu': '0',
2626
'number_of_floating_ips_per_project': "1",
2727
'vm_flavor': 'SCS-1L-1',
2828
'vm_image': 'Ubuntu 24.04',
2929
'vm_volume_size_gb': "10",
30+
'verify_ssl_certificate': "false",
3031
'cloud_init_extra_script': """#!/bin/bash\necho "HELLO WORLD"; date > READY; whoami >> READY""",
3132
'wait_for_server_timeout': "300",
3233
}
@@ -151,6 +152,14 @@ def get_admin_vm_ssh_key() -> str:
151152
def get_admin_domain_password() -> str:
152153
return Config.get("admin_domain_password", regex=r".{5,}")
153154

155+
@staticmethod
156+
def get_verify_ssl_certificate() ->bool:
157+
value = Config.get("verify_ssl_certificate", regex=r"true|false|True|False")
158+
if value.lower() == "false":
159+
return False
160+
else:
161+
return True
162+
154163
@staticmethod
155164
def configured_quota_names(quota_category: str) -> list[str]:
156165
if quota_category in Config._config:
@@ -221,7 +230,7 @@ def setup_logging(log_level: str) -> Tuple[logging.Logger, str]:
221230

222231

223232
def cloud_checker(value: str) -> str:
224-
if not re.fullmatch("[a-zA-Z0-9]+", value):
233+
if not re.fullmatch("[a-zA-Z0-9-]+", value):
225234
raise argparse.ArgumentTypeError('specify a value for os_cloud')
226235
return value
227236

src/openstack_workload_generator/entities/network.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,14 @@ def create_and_get_network(self) -> Network:
112112
if self.obj_network:
113113
return self.obj_network
114114

115+
mtu_size = Config.get_network_mtu()
116+
if mtu_size == 0:
117+
mtu = None
118+
115119
self.obj_network = self.conn.network.create_network(
116120
name=self.network_name,
117121
project_id=self.project.id,
118-
mtu=Config.get_network_mtu(),
122+
mtu=mtu_size,
119123
)
120124
if not self.obj_network:
121125
raise RuntimeError(f"Unable to create network {self.network_name}")

src/openstack_workload_generator/entities/project.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ def get_clouds_yaml_data(self) -> dict[str, str | dict[str, str]]:
305305
"user_domain_name": self.domain.name,
306306
"password": self.user.user_password,
307307
},
308+
"verify": Config.get_verify_ssl_certificate(),
308309
"cacert": self.project_conn.verify,
309310
"identity_api_version": "3",
310-
"endpoint_type": "internalURL"
311311
}
312312
return data

0 commit comments

Comments
 (0)