Skip to content

Commit

Permalink
fix: we don't want the env name in the flavor
Browse files Browse the repository at this point in the history
We don't want to be prefixing the flavor names with an environment name.
Just put the environment data in the correct place.
  • Loading branch information
cardoe committed Dec 9, 2024
1 parent 9166f39 commit be2c916
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 27 deletions.
20 changes: 1 addition & 19 deletions python/understack-flavor-matcher/flavor_matcher/flavor_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,15 @@ def from_yaml(yaml_str: str) -> "FlavorSpec":
pci=data.get("pci", []),
)

@staticmethod
def configured_envtype():
return os.getenv("FLAVORS_ENV", "unconfigured")

@property
def stripped_name(self):
"""Returns actual flavor name with the prod/nonprod prefix removed."""
_, name = self.name.split(".", 1)
if not name:
raise Exception(f"Unable to strip envtype from flavor: {self.name}")
return name

@property
def baremetal_nova_resource_class(self):
"""Returns flavor name converted to be used with Nova flavor resources.
https://docs.openstack.org/ironic/latest/install/configure-nova-flavors.html
"""
converted_name = re.sub(r"[^\w]", "_", self.stripped_name).upper()
converted_name = re.sub(r"[^\w]", "_", self.name).upper()
return f"resources:CUSTOM_BAREMETAL_{converted_name}"

@property
def env_type(self):
return self.name.split(".")[0]

@property
def memory_mib(self):
"""Returns memory size in MiB"""
Expand All @@ -80,8 +64,6 @@ def from_directory(directory: str = "/etc/flavors/") -> list["FlavorSpec"]:
with open(filepath, "r") as file:
yaml_content = file.read()
flavor_spec = FlavorSpec.from_yaml(yaml_content)
if flavor_spec.env_type != FlavorSpec.configured_envtype():
continue
flavor_specs.append(flavor_spec)
except yaml.YAMLError as e:
print(f"Error parsing YAML file {filename}: {e}")
Expand Down
6 changes: 0 additions & 6 deletions python/understack-flavor-matcher/tests/test_flavor_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def yaml_directory(tmp_path, valid_yaml, invalid_yaml):
def test_from_yaml(valid_yaml):
spec = FlavorSpec.from_yaml(valid_yaml)
assert spec.name == "nonprod.gp2.ultramedium"
assert spec.stripped_name == "gp2.ultramedium"
assert spec.manufacturer == "Dell"
assert spec.model == "PowerEdge R7615"
assert spec.memory_gb == 7777
Expand Down Expand Up @@ -332,8 +331,3 @@ def test_baremetal_nova_resource_class(valid_yaml):
flv.baremetal_nova_resource_class
== "resources:CUSTOM_BAREMETAL_GP2_ULTRAMEDIUM"
)


def test_envtype(valid_yaml):
flv = FlavorSpec.from_yaml(valid_yaml)
assert flv.env_type == "nonprod"
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ def guess_machine_flavor(device_info: ChassisInfo, bmc: Bmc) -> str:
raise Exception(
f"Machine: {machine} could not be classified into any flavor {FLAVORS=}"
)
logger.info(f"Device has been classified as flavor: {flavor_name.stripped_name}")
logger.info(f"Device has been classified as flavor: {flavor_name.name}")

return flavor_name.stripped_name
return flavor_name.name

0 comments on commit be2c916

Please sign in to comment.