Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
#
# 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.

# Keep the Galaxy builds
!cloudera-cloud-*.tar.gz

# Ignore the test output
tests/output

# Remove any integration configuration
tests/integration/integration_config.yml

# Remove the Sphinx build directory
site/_build

Expand Down
17 changes: 17 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
#
# 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.

[pytest]
filterwarnings =
ignore::DeprecationWarning
21 changes: 21 additions & 0 deletions tests/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
#
# 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.

# Support for this feature was first added in ansible-core 2.12.
# See:
# - https://github.com/ansible-collections/overview/issues/45#issuecomment-827853900
# - https://github.com/ansible/ansible/blob/devel/test/lib/ansible_test/config/config.yml

modules:
python_requires: '>=3.6'
35 changes: 35 additions & 0 deletions tests/integration/integration_config.yml.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---

# Copyright 2022 Cloudera, Inc. All Rights Reserved.
#
# 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.

# integration_config.yml

# Minimal cloudera.cloud configuration to construct a CDP testing environment
# Will recursively merge and overwrite any variables defined within a Target
# (i.e. vars/main.yml)

# You can use this file to create specific conditions for testing that are
# outside of a given target's configuration. Just be mindful that any changes
# here will proprogate to all targets, so depending on your testing and development,
# you might want to limit execution to specified targets.

# Specify any environment variables for modules and libraries like CDPCLI, etc.
env_vars:
#CDP_PROFILE: my-cdp-profile
CDP_ACCESS_KEY_ID: "foobarbaz"
CDP_PRIVATE_KEY: "1234567890"

# Parameters used by all functions of cloudera.cloud
env_name: example_env
19 changes: 19 additions & 0 deletions tests/integration/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
#
# 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.

# CDPCLI / cdpy
git+https://github.com/cloudera-labs/cdpy@main#egg=cdpy

# Upstream dependencies
#docutils==0.14 # Required by cdpcli-beta 0.9.59
17 changes: 17 additions & 0 deletions tests/integration/targets/environ/aliases
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022 Cloudera, Inc. All Rights Reserved.
#
# 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.

skip/python2
#setup/once/setup_infra
#needs/target/another
23 changes: 23 additions & 0 deletions tests/integration/targets/environ/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---

# Copyright 2022 Cloudera, Inc. All Rights Reserved.
#
# 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.

- name: Describe environment
cloudera.cloud.env_info:
name: "{{ env_name }}"
register: __env

- debug:
var: __env
26 changes: 26 additions & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

# Copyright 2022 Cloudera, Inc. All Rights Reserved.
#
# 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.

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import sys
import pytest

@pytest.fixture(autouse=True)
def skip_python():
if sys.version_info < (3, 6):
pytest.skip('Skipping on Python %s. cloudera.cloud supports Python 3.6 and higher.' % sys.version)
133 changes: 133 additions & 0 deletions tests/unit/plugins/modules/environment/test_env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# -*- coding: utf-8 -*-

# Copyright 2022 Cloudera, Inc. All Rights Reserved.
#
# 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.

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import pytest
import unittest

from unittest.mock import patch

from ansible_collections.cloudera.cloud.plugins.modules import env
from ansible_collections.cloudera.cloud.tests.unit.plugins.modules.utils import AnsibleExitJson, ModuleTestCase, setup_module_args


class TestEnvironment(ModuleTestCase):

def test_freeipa_specified(self):
setup_module_args({
'name': "unit-test",
'cloud': 'aws',
'region': 'fake_region',
'credential': 'fake_credential',
'public_key_id': 'fake_key',
'vpc_id': 'fake_vpc',
'subnet_ids': [ 'fake_subnet' ],
'default_sg': 'fake_default_sg',
'knox_sg': 'fake_knox_sg',
'log_location': 'fake_log_location',
'log_identity': 'fake_log_identity',
'wait': False,
'freeipa': { 'instanceCountByGroup': 3 }
})

expected = dict(
environmentName='unit-test',
credentialName='fake_credential',
region='fake_region',
enableTunnel=False,
workloadAnalytics=True,
logStorage=dict(
instanceProfile='fake_log_identity',
storageLocationBase='fake_log_location'
),
authentication=dict(
publicKeyId='fake_key'
),
vpcId='fake_vpc',
subnetIds=['fake_subnet'],
securityAccess=dict(
defaultSecurityGroupId='fake_default_sg',
securityGroupIdForKnox='fake_knox_sg'
),
freeIpa=dict(instanceCountByGroup=3)
)

with patch('cdpy.cdpy.CdpyEnvironments') as mocked_cdp:
mocked_cdp.return_value.describe_environment.return_value = None
mocked_cdp.return_value.create_aws_environment.return_value = { 'name': 'Successful test' }

with pytest.raises(AnsibleExitJson) as e:
env.main()

print("Returned: ", str(e.value))

mocked_cdp.return_value.describe_environment.assert_called_once_with('unit-test')
mocked_cdp.return_value.create_aws_environment.assert_called_once_with(**expected)

def test_freeipa_default(self):
setup_module_args({
'name': "unit-test",
'cloud': 'aws',
'region': 'fake_region',
'credential': 'fake_credential',
'public_key_id': 'fake_key',
'vpc_id': 'fake_vpc',
'subnet_ids': [ 'fake_subnet' ],
'default_sg': 'fake_default_sg',
'knox_sg': 'fake_knox_sg',
'log_location': 'fake_log_location',
'log_identity': 'fake_log_identity',
'wait': False
})

expected = dict(
environmentName='unit-test',
credentialName='fake_credential',
region='fake_region',
enableTunnel=False,
workloadAnalytics=True,
logStorage=dict(
instanceProfile='fake_log_identity',
storageLocationBase='fake_log_location'
),
authentication=dict(
publicKeyId='fake_key'
),
vpcId='fake_vpc',
subnetIds=['fake_subnet'],
securityAccess=dict(
defaultSecurityGroupId='fake_default_sg',
securityGroupIdForKnox='fake_knox_sg'
),
freeIpa=dict(instanceCountByGroup=2)
)

with patch('cdpy.cdpy.CdpyEnvironments') as mocked_cdp:
mocked_cdp.return_value.describe_environment.return_value = None
mocked_cdp.return_value.create_aws_environment.return_value = { 'name': 'Successful test' }

with pytest.raises(AnsibleExitJson) as e:
env.main()

print("Returned: ", str(e.value))

mocked_cdp.return_value.describe_environment.assert_called_once_with('unit-test')
mocked_cdp.return_value.create_aws_environment.assert_called_once_with(**expected)

if __name__ == '__main__':
unittest.main()
58 changes: 58 additions & 0 deletions tests/unit/plugins/modules/environment/test_env_i.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# -*- coding: utf-8 -*-

# Copyright 2022 Cloudera, Inc. All Rights Reserved.
#
# 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.

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type

import os
import pprint
import pytest
import unittest

from ansible_collections.cloudera.cloud.plugins.modules import env_info
from ansible_collections.cloudera.cloud.tests.unit.plugins.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, setup_module_args

ENV_NAME = "foobarbaz"


@unittest.skipUnless(os.getenv('CDP_PROFILE'), "CDP access parameters not set")
class TestEnvironmentIntegration(ModuleTestCase):

#@unittest.skip("Focus focus focus")
def test_list_all_environments(self):
setup_module_args({
"verify_tls": False
})

with pytest.raises(AnsibleExitJson) as e:
env_info.main()

pprint.pp(e.value)

def test_describe_environment(self):
setup_module_args({
"name": ENV_NAME,
"verify_tls": False
})

with pytest.raises(AnsibleExitJson) as e:
env_info.main()

assert len(e.value.args[0]['environments']) == 0
pprint.pp(e.value)

if __name__ == '__main__':
unittest.main()
Loading