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

Using Python for CI script and added smoke test after deployment. #91

Merged
merged 7 commits into from
May 3, 2018

Conversation

roperto
Copy link
Contributor

@roperto roperto commented Apr 30, 2018

For more information see Issue #77

@msftclas
Copy link

msftclas commented Apr 30, 2018

CLA assistant check
All CLA requirements met.

@roperto
Copy link
Contributor Author

roperto commented Apr 30, 2018

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 ARTIFACTS_LOCATION during the build, do you think that may be a problem?

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

Copy link

@hosungsmsft hosungsmsft left a 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))

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?

Copy link
Contributor Author

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?

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.

Copy link
Contributor Author

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

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!

secret=self.config.secret,
tenant=self.config.tenant_id,
)
self.resource_client = ResourceManagementClient(self.credentials, self.config.subscription_id)

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...

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 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.

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

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.

Copy link
Contributor Author

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.

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.

Copy link
Contributor Author

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

@hosungsmsft
Copy link

I'll still wait for your change to the smoke test to include a site login as the Moodle admin.

@roperto roperto force-pushed the issue77_moodle-deploy-test branch from 25336f2 to 3668961 Compare May 3, 2018 01:24
@roperto roperto force-pushed the issue77_moodle-deploy-test branch from 3668961 to f190ec8 Compare May 3, 2018 01:30
print('(got credentials)')
subscription_client = SubscriptionClient(self.credentials)
subscription = next(subscription_client.subscriptions.list())
print('(found subscription)')
Copy link
Contributor Author

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.

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!

@roperto
Copy link
Contributor Author

roperto commented May 3, 2018

Hi @hosungsmsft

I have now implemented:

  • artifacts location fix
  • auto-detect subscription id
  • login in Moodle as administrator

Please let me know your thoughts.

Cheers

print("(valid)")

def deploy(self):
print('\nDeploying template, feel free to take a nap...')

Choose a reason for hiding this comment

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

Funny! :)

Copy link

@hosungsmsft hosungsmsft left a comment

Choose a reason for hiding this comment

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

💯

@hosungsmsft hosungsmsft merged commit 02b96ef into Azure:master May 3, 2018
@hosungsmsft
Copy link

Fixes #77

@roperto roperto deleted the issue77_moodle-deploy-test branch May 4, 2018 05:22
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.

3 participants