Skip to content

Commit

Permalink
nova_flavors: stop using hardcoded IDs for auth
Browse files Browse the repository at this point in the history
  • Loading branch information
skrobul committed Nov 20, 2024
1 parent 01e05f2 commit 70a984f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
21 changes: 12 additions & 9 deletions operators/nova-flavors/nova_flavors/flavor_synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,28 @@ def __init__(
self,
username: str | None = "",
password: str = "",
project_id: str | None = None,
user_domain_id=None,
project_name: str | None = "admin",
project_domain_name: str = "default",
user_domain_name="service",
auth_url: str | None = None,
) -> None:
self.username = username
self.password = password
self.project_id = str(project_id)
self.user_domain_id = user_domain_id
self.project_name = str(project_name)
self.project_domain_name = str(project_domain_name)
self.user_domain_name = user_domain_name
self.auth_url = auth_url

@cached_property
def _nova(self):
return novaclient.Client(
"2",
self.username,
self.password,
self.project_id,
self.auth_url,
user_domain_id=self.user_domain_id,
username=self.username,
password=self.password,
project_name=self.project_name,
project_domain_name=self.project_domain_name,
user_domain_name=self.user_domain_name,
auth_url=self.auth_url,
)

def reconcile(self, desired_flavors: list[FlavorSpec]):
Expand Down
11 changes: 6 additions & 5 deletions operators/nova-flavors/nova_flavors/reconcile.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ def main():
if not os.path.isdir(flavors_dir):
raise ValueError(f"flavors_dir '{flavors_dir}' is not a directory")
synchronizer = FlavorSynchronizer(
username=os.environ.get("OS_USERNAME", ""),
password=os.environ.get("OS_PASSWORD", ""),
project_id=os.environ.get("OS_PROJECT_ID"),
user_domain_id=os.environ.get("OS_USER_DOMAIN_ID", ""),
auth_url=os.environ.get("OS_AUTH_URL"),
username=os.getenv("OS_USERNAME", ""),
password=os.getenv("OS_PASSWORD", ""),
project_name=os.getenv("OS_PROJECT_NAME", "admin"),
project_domain_name=os.getenv("OS_PROJECT_DOMAIN_NAME", "default"),
user_domain_name=os.getenv("OS_USER_DOMAIN_NAME", "service"),
auth_url=os.getenv("OS_AUTH_URL"),
)

handler = SpecChangedHandler(synchronizer, read_flavors)
Expand Down
5 changes: 1 addition & 4 deletions operators/nova-flavors/tests/test_flavor_synchronizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ def flavor_synchronizer():
return FlavorSynchronizer(
username="test_username",
password="test_password",
project_id="test_project_id",
user_domain_id="test_user_domain_id",
auth_url="test_auth_url",
)

Expand Down Expand Up @@ -46,8 +44,7 @@ def flavor():
def test_flavor_synchronizer_init(flavor_synchronizer):
assert flavor_synchronizer.username == "test_username"
assert flavor_synchronizer.password == "test_password"
assert flavor_synchronizer.project_id == "test_project_id"
assert flavor_synchronizer.user_domain_id == "test_user_domain_id"
assert flavor_synchronizer.user_domain_name == "service"
assert flavor_synchronizer.auth_url == "test_auth_url"


Expand Down

0 comments on commit 70a984f

Please sign in to comment.