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

[new module] Adding module azure_rm_sqldatabase #33173

Closed
wants to merge 7 commits into from

Conversation

zikalino
Copy link
Contributor

SUMMARY

Adding support for Azure SQL Databases

ISSUE TYPE
  • New Module Pull Request
COMPONENT NAME

azure_rm_sql_databases

ANSIBLE VERSION
ADDITIONAL INFORMATION

This module depends on azure_rm_sql_servers

@ansibot
Copy link
Contributor

ansibot commented Nov 22, 2017

cc @brusMX
click here for bot help

@ansibot ansibot added affects_2.5 This issue/PR affects Ansible v2.5 azure cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_module This PR includes a new module. new_plugin This PR includes a new plugin. support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests. labels Nov 22, 2017
@ansibot
Copy link
Contributor

ansibot commented Nov 22, 2017

@brusMX @devigned @haroldwongms @julienstroheker @jwhitbeck @lmazuel @obsoleted @ozboms @sozercan @tstringer @xscript @yuwzho

As a maintainer of a module in the same namespace this new module has been submitted to, your vote counts for shipits. Please review this module and add shipit if you would like to see it merged.

click here for bot help

@gundalow gundalow removed the needs_triage Needs a first human triage before being processed. label Nov 22, 2017
@ansibot
Copy link
Contributor

ansibot commented Nov 23, 2017

@zikalino this PR contains more than one new module.

Please submit only one new module per pullrequest. For further explanation, please read grouped module documentation

click here for bot help

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. labels Nov 23, 2017
Copy link
Contributor

@jborean93 jborean93 left a comment

Choose a reason for hiding this comment

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

I haven't tested this one yet but a lot of the comments I had for your azure_rm_sql_server also apply this this one here when it comes to the code. One area I think this needs to be improved on is the documentation. I started putting a few comments but they mostly apply to all the options and it all balls down to;

  • Don't copy and paste from docs as the option names don't match up to the Ansible side
  • Put the text after a . on a new line like in the examples I gave you
  • When talking about behaviour for different options, try and put them on their own sentance.
  • Expand the examples as there seems to be quite a few different ways of doing things

We should also look at changing the return values to only return what the user may not already know but we can look at that after we get the documentation updated and the tests expanded.

@@ -0,0 +1,443 @@
#!/usr/bin/python
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like you copied the original but didn't remove it :)

---
module: azure_rm_sql_database
version_added: "2.5"
short_description: Manage an Databases.
Copy link
Contributor

Choose a reason for hiding this comment

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

We don't put . on the short_description.

location:
description:
- Resource location.
required: True
Copy link
Contributor

Choose a reason for hiding this comment

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

Like with azure_sql_server, can we not require this and derive the location from the resource group if not specified?

required: False
create_mode:
description:
- "Specifies the mode of database creation.\n\nDefault: regular database creation.\n\nCopy: creates a database as a copy of an existing database.
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not copy and paste the values from the documentation and do something like.

create_mode:
  description:
  - Specifies the mode of the database creation.
  - C(Default) is a regular database creation
  - C(Copy) creates a database as a copy of an existing database, I(source_database_id) must be set in this mode.
  - C(OnlineSecondary) creates a database as a readable secondary replica, I(source_database_id) must be set in this mode.
  - ... continue for each option and state what needs to be set
  default: Default

ecovery point resource ID.\n\nCopy, NonReadableSecondary, OnlineSecondary and RestoreLongTermRetentionBackup are not supported for DataWarehou
se edition. Possible values include: 'Copy', 'Default', 'NonReadableSecondary', 'OnlineSecondary', 'PointInTimeRestore', 'Recovery', 'Restore'
, 'RestoreLongTermRetentionBackup'"
required: False
Copy link
Contributor

Choose a reason for hiding this comment

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

required: False not needed.

required: False
source_database_id:
description:
- "Conditional. If createMode is Copy, NonReadableSecondary, OnlineSecondary, PointInTimeRestore, Recovery, or Restore, then this value is requir
Copy link
Contributor

Choose a reason for hiding this comment

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

Split up as an entry per sentence instead of one long line, e.g.

source_database_id:
  description:
  - Specifies the resource ID of the source database.
  - If I(create_mode) is C(Copy), C(NonReadableSecondary), ...., then this must be set.
  - If I(create_mode) is C(NonReadableSecondary) or C(OnlineSecondary), the name of the source db must be the same as the new db.

Maybe even make it clearer whether this is the name of the database or the id, or both?

'''

EXAMPLES = '''
- name: Create (or update) Sql
Copy link
Contributor

Choose a reason for hiding this comment

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

A few things

  • Keep the examples left aligned (remove the leading 4 spaces)
  • Stop using jinja2 block {{}} in the examples so people can see what the actual may look like
  • Provide more than 1 example, usually we have a basic with only the parameters required, then 1 for each major scenario, like 1 for the main create_mode options and so on

@ansibot
Copy link
Contributor

ansibot commented Nov 29, 2017

The test ansible-test sanity --test pylint [?] failed with the following error:

lib/ansible/modules/cloud/azure/azure_rm_sql_database.py:907:43: undefined-variable Undefined variable 'cmp'

The test ansible-test sanity --test validate-modules [?] failed with the following errors:

lib/ansible/modules/cloud/azure/azure_rm_sql_database.py:717:0: E107 Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.
lib/ansible/modules/cloud/azure/azure_rm_sql_database.py:720:0: E107 Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.
lib/ansible/modules/cloud/azure/azure_rm_sql_database.py:721:0: E107 Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.
lib/ansible/modules/cloud/azure/azure_rm_sql_database.py:722:0: E107 Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.
lib/ansible/modules/cloud/azure/azure_rm_sql_database.py:723:0: E107 Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.

click here for bot help

@ansibot ansibot added the ci_verified Changes made in this PR are causing tests to fail. label Nov 29, 2017
@jborean93
Copy link
Contributor

One more name change as well, the common format is to use azure_rm_< resource name without _ >, in this case would be azure_rm_sqldatabase and the same thing would apply to the sql server module as well.

@ansibot ansibot removed the ci_verified Changes made in this PR are causing tests to fail. label Dec 5, 2017
@ansibot ansibot added the needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. label Dec 5, 2017
@ansibot
Copy link
Contributor

ansibot commented Dec 5, 2017

The test ansible-test sanity --test validate-modules [?] failed with the following errors:

lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py:716:0: E107 Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.
lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py:719:0: E107 Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.
lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py:720:0: E107 Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.
lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py:721:0: E107 Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.
lib/ansible/modules/cloud/azure/azure_rm_sqldatabase.py:722:0: E107 Imports should be directly below DOCUMENTATION/EXAMPLES/RETURN/ANSIBLE_METADATA.

click here for bot help

@ansibot ansibot added ci_verified Changes made in this PR are causing tests to fail. and removed needs_ci This PR requires CI testing to be performed. Please close and re-open this PR to trigger CI. labels Dec 5, 2017
@zikalino
Copy link
Contributor Author

zikalino commented Dec 5, 2017

ready_for_review

@ansibot ansibot added community_review In order to be merged, this PR must follow the community review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 5, 2017
@zikalino
Copy link
Contributor Author

zikalino commented Dec 6, 2017

fixed several major issues:

  • renaming, etc.
  • idempotence support
  • added update / idempotence tests
    I may have missed some smaller issues.
    Please recheck if still any important changes needed

Additional note - I still plan to add following adjustments in this PR:

  • flatten state in response (like in Contatiner Registry module)
  • add default values
  • flatten parameters

@ansibot ansibot added stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. stale_review Updates were made after the last review and the last review is more than 7 days old. labels Dec 15, 2017
@nitzmahone nitzmahone changed the title [new module] Adding module azure_rm_sql_databases [new module] Adding module azure_rm_sqldatabase Dec 18, 2017
Copy link
Contributor

@jborean93 jborean93 left a comment

Choose a reason for hiding this comment

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

Have put some comments, the main thing would be to add some more tests and fix up the documentation so it isn't just a copy and paste of some Azure docs and more related to the module itself.

@@ -0,0 +1,2 @@
cloud/azure
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 able to update this so it runs on the CI

location: eastus
admin_username: mylogin
admin_password: Testpasswordxyz12!
- name: Create instance of SQL Database
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 able to add a check mode and idempotent task for the create, update and delete tasks

version_added: "2.5"
short_description: Manage SQL Database instance
description:
- Create, update and delete instance of SQL Database
Copy link
Contributor

Choose a reason for hiding this comment

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

Full stop

description:
- The name of the database to be operated on (updated or created).
required: True
tags:
Copy link
Contributor

Choose a reason for hiding this comment

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

The extends documentation fragments azure_tags adds this option

- Resource tags.
location:
description:
- Resource location.
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the default value if not set, from the resource group?

self.log("Checking if the SQL Database instance {0} is present".format(self.name))
found = False
try:
response = self.mgmt_client.databases.get(self.resource_group,
Copy link
Contributor

Choose a reason for hiding this comment

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

kwargs

self.log("Need to Create / Update the SQL Database instance")

if self.check_mode:
return self.results
Copy link
Contributor

Choose a reason for hiding this comment

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

This would need results['changed'] = True in the create scenario. We really need a way to checking if we need to update the database instead of doing the operation and checking if it changed there as well.

if not old_response:
self.results['changed'] = True
else:
self.results['changed'] = old_response.__ne__(response)
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't really how we usually go update operations in Ansible. Is there way of checking if a change needs to occur and then making or rather than making a request and seeing if it was changed. The benefit of the former approach is that when running in check mode you can see if a change needs to happen while in this scenario you wouldn't know.

self.results['changed'] = True
else:
self.results['changed'] = old_response.__ne__(response)
self.results.update(response)
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't do this as you would need to pop all the results below. Just set results['id'] = response.... for each value you want to return to make it simpler.

assert:
that:
- output.changed
- output.status == 'Online'
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to check that some of the return values like id is defined, like so

- name: Assert the resource instance is created
  assert:
  that:
  - output.changed
  - output.status == 'Online'
  - output.id is defined
  - output.database_id is defined

@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed community_review In order to be merged, this PR must follow the community review workflow. stale_review Updates were made after the last review and the last review is more than 7 days old. labels Dec 21, 2017
@zikalino zikalino closed this Jan 10, 2018
@yungezz yungezz deleted the module-azure-rm-sql-databases branch August 31, 2018 01:53
@ansible ansible locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.5 This issue/PR affects Ansible v2.5 azure cloud module This issue/PR relates to a module. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. new_module This PR includes a new module. new_plugin This PR includes a new plugin. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. support:community This issue/PR relates to code supported by the Ansible community. test This PR relates to tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants