Skip to content

Commit

Permalink
[sdk 1.0] fix tests (#256)
Browse files Browse the repository at this point in the history
[sdk 1.0] fix tests

idea is to adopt SDK 1.0 and AOC 2.0
occasionally reworked of css cluster info module and added dns zone info module.

Reviewed-by: Anton Sidelnikov
Reviewed-by: Polina Gubina
  • Loading branch information
vladimirvshivkov authored Feb 13, 2023
1 parent 4338847 commit 12c8558
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 44 deletions.
2 changes: 1 addition & 1 deletion galaxy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace: opentelekomcloud
name: cloud
version: 0.12.4
version: 0.13.1
readme: README.md
authors:
- Artem Goncharov <[email protected]>
Expand Down
47 changes: 17 additions & 30 deletions plugins/modules/css_cluster_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
short_description: Get info about CSS clusters.
extends_documentation_fragment: opentelekomcloud.cloud.otc
version_added: "0.9.0"
author: "Yustina Kvrivishvili (@YustinaKvr)"
author:
- "Yustina Kvrivishvili (@YustinaKvr)"
- "Vladimir Vshivkov (@vladimirvshivkov)"
description:
- Get CSS cluster info from the OTC.
options:
Expand Down Expand Up @@ -184,11 +186,10 @@


class CSSClusterInfoModule(OTCModule):

argument_spec = dict(
name=dict(required=False),
start=dict(required=False, type='int', default=1),
limit=dict(required=False, type='int')
name=dict(),
start=dict(type='int', default=1),
limit=dict(type='int')
)
module_kwargs = dict(
supports_check_mode=True
Expand All @@ -197,33 +198,19 @@ class CSSClusterInfoModule(OTCModule):
otce_min_version = '0.24.1'

def run(self):

data = []
query = {}

if self.params['start']:
query['start'] = self.params['start']
if self.params['limit']:
query['limit'] = self.params['limit']

if self.params['name']:
raw = self.conn.css.find_cluster(
name_or_id=self.params['name'],
ignore_missing=True)
if raw:
dt = raw.to_dict()
dt.pop('location')
data.append(dt)
name = self.params['name']
if name:
css_clusters = self.conn.css.find_cluster(name)
else:
for raw in self.conn.css.clusters(**query):
dt = raw.to_dict()
dt.pop('location')
data.append(dt)
kwargs = {k: self.params[k]
for k in ['start', 'limit']
if self.params[k] is not None}

raw = self.conn.css.clusters(**kwargs)
css_clusters = [c.to_dict(computed=False) for c in raw]

self.exit(
changed=False,
clusters=data
)
self.exit_json(changed=False,
css_clusters=css_clusters)


def main():
Expand Down
116 changes: 116 additions & 0 deletions plugins/modules/dns_zone_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
#!/usr/bin/python
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

DOCUMENTATION = '''
module: dns_zone_info
short_description: Get DNS Zones info
extends_documentation_fragment: opentelekomcloud.cloud.otc
version_added: "0.13.1"
author: "Vladimir Vshivkov (@vladimirvshivkov)"
description:
- Get DNS Zones info from the OTC.
options:
name:
description:
- Zone Name
type: str
required: true
zone_type:
description:
- Zone Type, either public or private
type: str
requirements: ["openstacksdk", "otcextensions"]
'''

RETURN = '''
zone:
description: Modify DNS Zones
type: complex
returned: On Success.
contains:
description:
description: Description of the Zone
type: str
sample: "MyZone123"
email:
description: assigned E-Mail of the Zone
type: str
sample: "[email protected]"
id:
description: Zone ID
type: str
sample: "fe80804323f2065d0175980e81617c10"
name:
description: Name of the zone
type: str
sample: "test.test2."
router:
description: Assigned VPC
type: list
sample: "[
router_id: 79c32783-e560-4e3a-95b1-5a0756441e12,
router_region: eu-de,
status: PENDING_CREATE
]"
status:
description: Resource status
type: str
sample: "PENDING_CREATE"
ttl:
description: Cache duration (in second) on a local DNS server
type: int
sample: 300
zone_type:
description: Zone Type, either public or private
type: str
sample: "private"
'''

EXAMPLES = '''
# Get a Zone:
- name: Testing
opentelekomcloud.cloud.dns_zone_info:
name: "test.com."
zone_type: private
'''

from ansible_collections.opentelekomcloud.cloud.plugins.module_utils.otc import OTCModule


class DNSZonesInfoModule(OTCModule):
argument_spec = dict(
name=dict(required=True),
zone_type=dict()
)
module_kwargs = dict(
supports_check_mode=True
)

def run(self):
query = {
'type': self.params['zone_type'],
'name_or_id': self.params['name']
}

zone = self.conn.dns.find_zone(**query)
self.exit(changed=True, zone=zone.to_dict())


def main():
module = DNSZonesInfoModule()
module()


if __name__ == '__main__':
main()
8 changes: 4 additions & 4 deletions test-requirements-2.9.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
ansible
ansible==7.2.0
ansible-lint
openstacksdk
pycodestyle==2.6.0
pycodestyle==2.10.0
flake8==3.8.4
pylint
voluptuous
voluptuous==0.13.1
yamllint
rstcheck
ruamel.yaml
tox
otcextensions
otcextensions==0.29
2 changes: 1 addition & 1 deletion test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ voluptuous
yamllint
rstcheck
ruamel.yaml
otcextensions>=0.10.0
otcextensions==0.29
4 changes: 2 additions & 2 deletions tests/integration/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
otcextensions<=0.26.3
openstacksdk<=0.61.0
otcextensions
openstacksdk
1 change: 1 addition & 0 deletions tests/integration/targets/deh_host/aliases
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
deh/group1
disabled
11 changes: 8 additions & 3 deletions tests/integration/targets/dns_private/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
ansible.builtin.debug:
var: dns_zo_pr.zone

- name: check zone is created
opentelekomcloud.cloud.dns_zone_info:
name: "{{ dns_zo_pr.zone.id }}"
register: dns_zo_info

- name: assert result
ansible.builtin.assert:
that:
Expand All @@ -76,7 +81,7 @@

- name: Updating a private DNS Zone - check mode
opentelekomcloud.cloud.dns_zone:
name: "{{ zone_private_name }}"
name: "{{ dns_zo_pr.zone.id }}"
state: present
description: "{{ description }}"
zone_type: "private"
Expand All @@ -91,7 +96,7 @@

- name: Updating a private DNS Zone
opentelekomcloud.cloud.dns_zone:
name: "{{ zone_private_name }}"
name: "{{ dns_zo_pr.zone.id }}"
state: present
description: "{{ description }}"
zone_type: "private"
Expand Down Expand Up @@ -123,7 +128,7 @@
block:
- name: Drop DNS private Zone
opentelekomcloud.cloud.dns_zone:
name: "{{ zone_private_name }}"
name: "{{ dns_zo_pr.zone.id }}"
zone_type: "private"
state: absent
register: dns_zo_pr_dr
Expand Down
9 changes: 7 additions & 2 deletions tests/integration/targets/dns_public/tasks/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@
- dns_zo is success
- dns_zo.zone is defined

- name: check zone is created
opentelekomcloud.cloud.dns_zone_info:
name: "{{ dns_zo.zone.id }}"
register: dns_zo_info

- name: Updating a public DNS Zone - check mode
opentelekomcloud.cloud.dns_zone:
name: "{{ zone_public_name }}"
name: "{{ dns_zo.zone.id }}"
state: present
description: "{{ description }}"
check_mode: true
Expand All @@ -130,7 +135,7 @@

- name: Updating a public DNS Zone
opentelekomcloud.cloud.dns_zone:
name: "{{ zone_public_name }}"
name: "{{ dns_zo.zone.id }}"
state: present
description: "{{ description }}"
register: dns_zo
Expand Down
1 change: 1 addition & 0 deletions tests/sanity/ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ plugins/modules/dms_queue_group_info.py validate-modules:missing-gplv3-license
plugins/modules/dns_floating_ip.py validate-modules:missing-gplv3-license
plugins/modules/dns_recordset.py validate-modules:missing-gplv3-license
plugins/modules/dns_zone.py validate-modules:missing-gplv3-license
plugins/modules/dns_zone_info.py validate-modules:missing-gplv3-license
plugins/modules/dns_recordset_info.py validate-modules:missing-gplv3-license
plugins/modules/deh_host.py validate-modules:missing-gplv3-license
plugins/modules/deh_host_info.py validate-modules:missing-gplv3-license
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
openstacksdk
otcextensions >= 0.7.1
otcextensions

0 comments on commit 12c8558

Please sign in to comment.