Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove hardcoded nova-compute app name and add ceph keys test #1141

Conversation

rodrigogansobarbieri
Copy link
Contributor

WIP

@rodrigogansobarbieri rodrigogansobarbieri force-pushed the zaza_nova_compute_refactor branch 2 times, most recently from 6109617 to d832962 Compare September 28, 2023 14:36
Copy link
Contributor Author

@rodrigogansobarbieri rodrigogansobarbieri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs updates

@@ -470,10 +481,50 @@ def test_901_pause_resume(self):
with self.pause_resume(['nova-compute']):
logging.info("Testing pause resume")

def test_904_test_ceph_keys(self):
"""Run pause and resume tests.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

docstring needs to be a proper one instead of this copy-pasted crap

self.assertNotEqual(v, result[1])
key_dict[result[0]] = result[1]

check_keyring([{self.application_name: [self.application_name]}])
Copy link
Contributor Author

@rodrigogansobarbieri rodrigogansobarbieri Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this was coded for stable/yoga where it does not have the partial fix that is on master. This needs to be adjusted to be able to run against the code on master.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I was going to ask about this, is the typical argument just a list of dictionaries like:

[{'nova-compute': ['nova-compute']}]

And then L500 above is just iterating through that? Seems it could be simplified if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rewrote that logic in the new version I am going to push soon

Copy link

@brianphaley brianphaley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had a question on the test you added, otherwise looks good.

@@ -372,7 +380,7 @@ def wait_for_nova_compute_count(expected_count):

# Wait for nova-compute service to be removed from the
# nova-cloud-controller
if not wait_for_nova_compute_count(0):
if not wait_for_nova_compute_count(service_count-1):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the (hidden) code above this, service_count must either be 0 or 1, so this change and below aren't actually necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need whitespace around the '-'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that is "future code", removing hardcoded values without changing the behavior, and keeping it ready to support more than 1 unit

self.assertNotEqual(v, result[1])
key_dict[result[0]] = result[1]

check_keyring([{self.application_name: [self.application_name]}])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I was going to ask about this, is the typical argument just a list of dictionaries like:

[{'nova-compute': ['nova-compute']}]

And then L500 above is just iterating through that? Seems it could be simplified if so.

unit, keyring_file))

result = regex.findall(data)
self.assertEqual(2, len(result))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: might be more obvious if you pull the key/value out here:

app_name, app_value = result

But just a nit

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would raise value error if the length is different. The assert validation is less imprecise as an error message.

result.append(app_name)
except KeyError:
# Older juju versions may not have the field "charm-name"
if charm_name in app_data['charm']:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do older versions return a list here for app_data['charm']? If not then a
simple string comparison such as you used a few lines above would be better.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the value here could be 'nova-compute-kvm' for example, so we are checking if the 'nova-compute' string is contained in app_data['charm'] string

}
for app in ('nova-compute', 'nova-cloud-controller',):
for app in (nova_compute_app_name, 'nova-cloud-controller',):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be misunderstanding the intent here, but if you anticipate that there
might be several apps that use the nova-compute charm, wouldn't you want to
restart services on all of those? However, you only store the first application
in line 191.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, that was partial future-proofing code, it is easy to make it fully future proof, making those changes now. I was initially just fixing the error where it was hardcoded.

if charm_name == app_data['charm-name']:
result.append(app_name)
except KeyError:
# Older juju versions may not have the field "charm-name"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see references to "charm-name" as far back as juju 1.25 and it is definitely in 2.3, maybe this is overkill?

Copy link
Contributor Author

@rodrigogansobarbieri rodrigogansobarbieri Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have seen juju status json without this field while coding probelius, then a later juju update introduced this field consistently. A bit overkill probably, but harmless I suppose. Given this is a CI code then I guess it is ok to remove and keep only what we expect to be the latest.

@rodrigogansobarbieri rodrigogansobarbieri changed the title [WIP] Remove hardcoded nova-compute app name and add ceph keys test Remove hardcoded nova-compute app name and add ceph keys test Oct 3, 2023
@rodrigogansobarbieri rodrigogansobarbieri force-pushed the zaza_nova_compute_refactor branch from fd40e90 to 76a2b81 Compare October 3, 2023 15:36
Copy link

@brianphaley brianphaley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, will see what others think

for unit in zaza.model.get_units('nova-compute',
model_name=self.model_name):
for unit in zaza.model.get_units(
self.application_name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure that self.application_name is being set to the name of the application in the same way as get_app_names_for_charm()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is somewhat similar. The base class code that assigns self.application_name checks if each app starts with the charm_name declared in tests.yaml, and it breaks when it finds the first one. We could remove the break and go on creating a "self.application_nameS" variable and we ultimately have the same as get_app_names_for_charm. Ultimately I'd prefer if it uses "in (contains)" instead of startswith though.

@rodrigogansobarbieri
Copy link
Contributor Author

Closed the PR as we don't intend to refactor this at the moment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants