Skip to content

Commit

Permalink
nova_flavors: remove awkward global
Browse files Browse the repository at this point in the history
  • Loading branch information
skrobul committed Nov 20, 2024
1 parent b8dd822 commit a615166
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
3 changes: 3 additions & 0 deletions operators/nova-flavors/nova_flavors/flavor_synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def _nova(self):
)

def reconcile(self, desired_flavors: list[FlavorSpec]):
if len(desired_flavors) < 1:
raise Exception(f"Empty desired_flavors list.")

existing_flavors = self._nova.flavors.list()
for flavor in desired_flavors:
nova_flavor = next(
Expand Down
11 changes: 3 additions & 8 deletions operators/nova-flavors/nova_flavors/reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@
logger = setup_logger(__name__, level=loglevel)


flavors_dir = ""


def read_flavors():
return FlavorSpec.from_directory(flavors_dir)


def main():
# nonprod vs prod
flavors_dir = os.getenv("FLAVORS_DIR", "")
Expand All @@ -35,7 +28,9 @@ def main():
auth_url=os.getenv("OS_AUTH_URL"),
)

handler = SpecChangedHandler(synchronizer, read_flavors)
handler = SpecChangedHandler(
synchronizer, lambda: FlavorSpec.from_directory(flavors_dir)
)
observer = Observer()
observer.schedule(handler, flavors_dir, recursive=True)
logger.info(f"Watching for changes in {flavors_dir}")
Expand Down
25 changes: 0 additions & 25 deletions operators/nova-flavors/tests/test_reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
from unittest.mock import patch

from nova_flavors.reconcile import (
FlavorSpec,
FlavorSynchronizer,
SpecChangedHandler,
main,
read_flavors,
)
from watchdog.observers import Observer

Expand All @@ -30,29 +28,6 @@ def test_flavors_dir_env_var_not_set(mocker, return_value):
main()


@patch.dict(
"os.environ",
{
"FLAVORS_ENV": "testenv",
"NOVA_FLAVOR_MONITOR_LOGLEVEL": "info",
"FLAVORS_DIR": "/",
},
)
def test_read_flavors(mocker):
# Set up
mock_flavor_spec = mocker.Mock(spec=FlavorSpec)
mocker.patch(
"nova_flavors.reconcile.FlavorSpec.from_directory",
return_value=mock_flavor_spec,
)

# Execute
result = read_flavors()

# Verify
assert result == mock_flavor_spec


@patch.dict(
"os.environ",
{
Expand Down

0 comments on commit a615166

Please sign in to comment.