-
Notifications
You must be signed in to change notification settings - Fork 166
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
Using Python for CI script and added smoke test after deployment. #91
Conversation
Hi @hosungsmsft This pull request changes the CI to use Azure Python SDK and adds a smoke test (check HTTP status) for the newly created Moodle instance. Please note I am not sending in Python the Also, using Azure CLI it was not necessary to provide a subscription ID, is it something you think the python script should try to detect instead of requesting as a parameter? As a final note, this still doesn't address issue #90 , but I believe this is an easy-pick to fix if you want it next. I'll wait for your feedback, Daniel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @roperto
Thanks for your PR. Please see my comments. Not sure about ARTIFACTS_LOCATION
, but the _artifactsLocation
parameter must be properly composed and overridden with the correct fork name and the branch name. Otherwise, all the nested templates will be pulled from the Azure/Moodle:master, not from the PR or the commit, so the test deployment will be inconsistent. Please see the original bash script about how to get the correct URL for _artifactsLocation
(something like SLUG_NAME
).
print("*** DEPLOY FAILED ***") | ||
print('HTTP Status Code: ' + status) | ||
sys.exit(1) | ||
print('(ok: {})'.format(status)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we try just one more here -- Login to the site as the admin user and see if works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I perform a login as admin, it would be interesting to go to the notifications and check if there is any error detected by Moodle as well. I'll see if its reasonable to do that and ping you back.
For now I could probably do it only with curl. Are we planning to add further tests later -- would it have any value to use selenium in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not much to add further tests in the future, but I wanted to make sure at this point that the database is also correctly installed/deployed/configured. A successful Moodle admin login will show that to us, so that's why I'm asking. Using curl should be just fine. We won't be using a too like selenium in the future, at least no plan currently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A get in the index by itself does test the DB conectivity and many subsystems of Moodle because they are required even for a simple "login page" rendering (there are authentication settings for example stored in the database).
In any case, I implemented a CURL (with follow redirects) to ensure Admin could login and gets to its front page, that gives some extra assertions that the framework is not corrupt. See https://github.com/Azure/Moodle/pull/91/files#diff-0800a30435a8e602ff7bf8df45fc6e09R131
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great to know that hitting the index.php does perform important operations. Thanks for your education. Also thanks much for your admin login check as well!
etc/travis/DeploymentTester.py
Outdated
secret=self.config.secret, | ||
tenant=self.config.tenant_id, | ||
) | ||
self.resource_client = ResourceManagementClient(self.credentials, self.config.subscription_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this seems to be the only place where the subscription ID is needed here, just because of this Python SDK API's requirement. However, a service principal is always associated with an Azure resource ID, which always includes a subscription, so that's why we didn't need to specify a subscription ID in the bash script. I wonder if we can somehow avoid having to provide a subscription ID here? Not a big deal, but just wondering...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not very familiar with the the Azure API in Python, but I'd guess it is possible to find out somehow. I'll investigate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just mentioning again that this is not a must. If it takes more than half an hour of your time, please disregard this comment.
with open('azuredeploy.parameters.json', 'r') as parameters_fd: | ||
parameters = json.load(parameters_fd) | ||
parameters = parameters['parameters'] | ||
parameters['sshPublicKey']['value'] = self.ssh_key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do need to override the _artifactsLocation parameter here with the correct fork name and the branch name. Otherwise, only the top-level template file (azuredeploy.json) will be from this PR/commit, and all the nested templates will be pulled from Azure/Moodle:master, which is wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies for not understanding the reason for that parameter before, that's the main reason why I asked why we need it. I'll fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's OK. I should also probably have let you keep using bash, not rewriting the same things in Python anyway. Your fix looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a minor change to the logic, but the idea stays the same
I'll still wait for your change to the smoke test to include a site login as the Moodle admin. |
25336f2
to
3668961
Compare
3668961
to
f190ec8
Compare
print('(got credentials)') | ||
subscription_client = SubscriptionClient(self.credentials) | ||
subscription = next(subscription_client.subscriptions.list()) | ||
print('(found subscription)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@hosungsmsft These lines should do the trick to fetch the first subscription (most likely the only one) available for a given service principal so I removed the configurable option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent! Thanks much for your research and improvement!
Hi @hosungsmsft I have now implemented:
Please let me know your thoughts. Cheers |
print("(valid)") | ||
|
||
def deploy(self): | ||
print('\nDeploying template, feel free to take a nap...') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Funny! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
Fixes #77 |
For more information see Issue #77