Skip to content

Commit dd54fc4

Browse files
authored
Add testing frameworks
Add integration and unit test framework Signed-off-by: Webster Mudge <wmudge@cloudera.com>
1 parent fb86d84 commit dd54fc4

File tree

12 files changed

+444
-0
lines changed

12 files changed

+444
-0
lines changed

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
1+
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
# Keep the Galaxy builds
216
!cloudera-cloud-*.tar.gz
317

18+
# Ignore the test output
19+
tests/output
20+
21+
# Remove any integration configuration
22+
tests/integration/integration_config.yml
23+
424
# Remove the Sphinx build directory
525
site/_build
626

pytest.ini

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
[pytest]
16+
filterwarnings =
17+
ignore::DeprecationWarning

tests/config.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Support for this feature was first added in ansible-core 2.12.
16+
# See:
17+
# - https://github.com/ansible-collections/overview/issues/45#issuecomment-827853900
18+
# - https://github.com/ansible/ansible/blob/devel/test/lib/ansible_test/config/config.yml
19+
20+
modules:
21+
python_requires: '>=3.6'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
3+
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# integration_config.yml
18+
19+
# Minimal cloudera.cloud configuration to construct a CDP testing environment
20+
# Will recursively merge and overwrite any variables defined within a Target
21+
# (i.e. vars/main.yml)
22+
23+
# You can use this file to create specific conditions for testing that are
24+
# outside of a given target's configuration. Just be mindful that any changes
25+
# here will proprogate to all targets, so depending on your testing and development,
26+
# you might want to limit execution to specified targets.
27+
28+
# Specify any environment variables for modules and libraries like CDPCLI, etc.
29+
env_vars:
30+
#CDP_PROFILE: my-cdp-profile
31+
CDP_ACCESS_KEY_ID: "foobarbaz"
32+
CDP_PRIVATE_KEY: "1234567890"
33+
34+
# Parameters used by all functions of cloudera.cloud
35+
env_name: example_env

tests/integration/requirements.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# CDPCLI / cdpy
16+
git+https://github.com/cloudera-labs/cdpy@main#egg=cdpy
17+
18+
# Upstream dependencies
19+
#docutils==0.14 # Required by cdpcli-beta 0.9.59
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
skip/python2
16+
#setup/once/setup_infra
17+
#needs/target/another
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
3+
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
- name: Describe environment
18+
cloudera.cloud.env_info:
19+
name: "{{ env_name }}"
20+
register: __env
21+
22+
- debug:
23+
var: __env

tests/unit/conftest.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from __future__ import (absolute_import, division, print_function)
18+
__metaclass__ = type
19+
20+
import sys
21+
import pytest
22+
23+
@pytest.fixture(autouse=True)
24+
def skip_python():
25+
if sys.version_info < (3, 6):
26+
pytest.skip('Skipping on Python %s. cloudera.cloud supports Python 3.6 and higher.' % sys.version)
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from __future__ import (absolute_import, division, print_function)
18+
__metaclass__ = type
19+
20+
import pytest
21+
import unittest
22+
23+
from unittest.mock import patch
24+
25+
from ansible_collections.cloudera.cloud.plugins.modules import env
26+
from ansible_collections.cloudera.cloud.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, setup_module_args
27+
28+
29+
class TestEnvironment(ModuleTestCase):
30+
31+
def test_freeipa_specified(self):
32+
setup_module_args({
33+
'name': "unit-test",
34+
'cloud': 'aws',
35+
'region': 'fake_region',
36+
'credential': 'fake_credential',
37+
'public_key_id': 'fake_key',
38+
'vpc_id': 'fake_vpc',
39+
'subnet_ids': [ 'fake_subnet' ],
40+
'default_sg': 'fake_default_sg',
41+
'knox_sg': 'fake_knox_sg',
42+
'log_location': 'fake_log_location',
43+
'log_identity': 'fake_log_identity',
44+
'wait': False,
45+
'freeipa': { 'instanceCountByGroup': 3 }
46+
})
47+
48+
expected = dict(
49+
environmentName='unit-test',
50+
credentialName='fake_credential',
51+
region='fake_region',
52+
enableTunnel=False,
53+
workloadAnalytics=True,
54+
logStorage=dict(
55+
instanceProfile='fake_log_identity',
56+
storageLocationBase='fake_log_location'
57+
),
58+
authentication=dict(
59+
publicKeyId='fake_key'
60+
),
61+
vpcId='fake_vpc',
62+
subnetIds=['fake_subnet'],
63+
securityAccess=dict(
64+
defaultSecurityGroupId='fake_default_sg',
65+
securityGroupIdForKnox='fake_knox_sg'
66+
),
67+
freeIpa=dict(instanceCountByGroup=3)
68+
)
69+
70+
with patch('cdpy.cdpy.CdpyEnvironments') as mocked_cdp:
71+
mocked_cdp.return_value.describe_environment.return_value = None
72+
mocked_cdp.return_value.create_aws_environment.return_value = { 'name': 'Successful test' }
73+
74+
with pytest.raises(AnsibleExitJson) as e:
75+
env.main()
76+
77+
print("Returned: ", str(e.value))
78+
79+
mocked_cdp.return_value.describe_environment.assert_called_once_with('unit-test')
80+
mocked_cdp.return_value.create_aws_environment.assert_called_once_with(**expected)
81+
82+
def test_freeipa_default(self):
83+
setup_module_args({
84+
'name': "unit-test",
85+
'cloud': 'aws',
86+
'region': 'fake_region',
87+
'credential': 'fake_credential',
88+
'public_key_id': 'fake_key',
89+
'vpc_id': 'fake_vpc',
90+
'subnet_ids': [ 'fake_subnet' ],
91+
'default_sg': 'fake_default_sg',
92+
'knox_sg': 'fake_knox_sg',
93+
'log_location': 'fake_log_location',
94+
'log_identity': 'fake_log_identity',
95+
'wait': False
96+
})
97+
98+
expected = dict(
99+
environmentName='unit-test',
100+
credentialName='fake_credential',
101+
region='fake_region',
102+
enableTunnel=False,
103+
workloadAnalytics=True,
104+
logStorage=dict(
105+
instanceProfile='fake_log_identity',
106+
storageLocationBase='fake_log_location'
107+
),
108+
authentication=dict(
109+
publicKeyId='fake_key'
110+
),
111+
vpcId='fake_vpc',
112+
subnetIds=['fake_subnet'],
113+
securityAccess=dict(
114+
defaultSecurityGroupId='fake_default_sg',
115+
securityGroupIdForKnox='fake_knox_sg'
116+
),
117+
freeIpa=dict(instanceCountByGroup=2)
118+
)
119+
120+
with patch('cdpy.cdpy.CdpyEnvironments') as mocked_cdp:
121+
mocked_cdp.return_value.describe_environment.return_value = None
122+
mocked_cdp.return_value.create_aws_environment.return_value = { 'name': 'Successful test' }
123+
124+
with pytest.raises(AnsibleExitJson) as e:
125+
env.main()
126+
127+
print("Returned: ", str(e.value))
128+
129+
mocked_cdp.return_value.describe_environment.assert_called_once_with('unit-test')
130+
mocked_cdp.return_value.create_aws_environment.assert_called_once_with(**expected)
131+
132+
if __name__ == '__main__':
133+
unittest.main()
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
from __future__ import (absolute_import, division, print_function)
18+
__metaclass__ = type
19+
20+
import os
21+
import pprint
22+
import pytest
23+
import unittest
24+
25+
from ansible_collections.cloudera.cloud.plugins.modules import env_info
26+
from ansible_collections.cloudera.cloud.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, setup_module_args
27+
28+
ENV_NAME = "foobarbaz"
29+
30+
31+
@unittest.skipUnless(os.getenv('CDP_PROFILE'), "CDP access parameters not set")
32+
class TestEnvironmentIntegration(ModuleTestCase):
33+
34+
#@unittest.skip("Focus focus focus")
35+
def test_list_all_environments(self):
36+
setup_module_args({
37+
"verify_tls": False
38+
})
39+
40+
with pytest.raises(AnsibleExitJson) as e:
41+
env_info.main()
42+
43+
pprint.pp(e.value)
44+
45+
def test_describe_environment(self):
46+
setup_module_args({
47+
"name": ENV_NAME,
48+
"verify_tls": False
49+
})
50+
51+
with pytest.raises(AnsibleExitJson) as e:
52+
env_info.main()
53+
54+
assert len(e.value.args[0]['environments']) == 0
55+
pprint.pp(e.value)
56+
57+
if __name__ == '__main__':
58+
unittest.main()

0 commit comments

Comments
 (0)