diff --git a/operators/nova-flavors/nova_flavors/flavor_synchronizer.py b/operators/nova-flavors/nova_flavors/flavor_synchronizer.py index 288e1d714..a84a6e894 100644 --- a/operators/nova-flavors/nova_flavors/flavor_synchronizer.py +++ b/operators/nova-flavors/nova_flavors/flavor_synchronizer.py @@ -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( diff --git a/operators/nova-flavors/nova_flavors/reconcile.py b/operators/nova-flavors/nova_flavors/reconcile.py index e87beb790..f1d097eb4 100644 --- a/operators/nova-flavors/nova_flavors/reconcile.py +++ b/operators/nova-flavors/nova_flavors/reconcile.py @@ -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", "") @@ -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}") diff --git a/operators/nova-flavors/tests/test_reconcile.py b/operators/nova-flavors/tests/test_reconcile.py index 7e21a192e..7734ee77a 100644 --- a/operators/nova-flavors/tests/test_reconcile.py +++ b/operators/nova-flavors/tests/test_reconcile.py @@ -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 @@ -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", {