def test_download_should_fail(self):
        self.resource.get_by_name.return_value = None
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_DOWNLOAD)

        ArtifactBundleModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY, msg=ArtifactBundleModule.MSG_REQUIRED)
    def test_backup_extract_should_fail(self):
        self.resource.get_all_backups.return_value = []
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_BACKUP_EXTRACT)

        ArtifactBundleModule().run()

        self.mock_ansible_module.fail_json.assert_called_once_with(
            exception=mock.ANY, msg=ArtifactBundleModule.MSG_BACKUP_REQUIRED)
    def test_should_do_nothing_when_resource_already_absent(self):
        self.resource.get_by_name.return_value = None
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_ABSENT)

        ArtifactBundleModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ArtifactBundleModule.MSG_ALREADY_ABSENT,
        )
    def test_should_not_update_when_existing_data_is_equals(self):
        self.resource.data = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_PRESENT)

        ArtifactBundleModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ArtifactBundleModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(artifact_bundle=DICT_DEFAULT_ARTIFACT_BUNDLE))
    def test_should_download(self):
        self.resource.data = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.resource.download.return_value = True
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_DOWNLOAD)

        ArtifactBundleModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ArtifactBundleModule.MSG_DOWNLOADED,
            ansible_facts=dict())
    def test_should_extract(self):
        self.resource.data = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.resource.extract.return_value = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_EXTRACT)

        ArtifactBundleModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_EXTRACTED,
            ansible_facts=dict(artifact_bundle=DICT_DEFAULT_ARTIFACT_BUNDLE))
    def test_should_delete_when_resource_exist(self):
        self.resource.data = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.resource.delete.return_value = True
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_ABSENT)

        ArtifactBundleModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_DELETED,
        )
示例#8
0
    def test_create_artifact_bundle(self):
        self.resource.get_by.return_value = []
        self.resource.create.return_value = self.ARTIFACT_BUNDLE
        self.mock_ansible_module.params = self.TASK_CREATE

        ArtifactBundleModule().run()

        self.resource.create.assert_called_once_with(self.ARTIFACT_BUNDLE)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_CREATED,
            ansible_facts=dict(artifact_bundle=self.ARTIFACT_BUNDLE))
    def test_should_do_nothing_when_already_absent(self):
        self.i3s.artifact_bundles.get_by.return_value = []

        self.mock_ansible_module.params = self.TASK_REMOVE

        ArtifactBundleModule().run()

        self.i3s.artifact_bundles.delete.not_been_called()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ArtifactBundleModule.MSG_ALREADY_ABSENT,
        )
    def test_should_upload_backup(self):
        self.resource.data = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.resource.upload_backup_bundle_from_file.return_value = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_BACKUP_UPLOAD)

        ArtifactBundleModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_BACKUP_UPLOADED,
            ansible_facts=dict(
                artifact_bundle_deployment_group=DICT_DEFAULT_ARTIFACT_BUNDLE))
    def test_should_do_nothing_when_no_newname_provided(self):
        self.i3s.artifact_bundles.get_by.return_value = [self.ARTIFACT_BUNDLE]
        self.mock_ansible_module.params = self.TASK_CREATE

        ArtifactBundleModule().run()

        self.i3s.artifact_bundles.create.not_been_called()
        self.i3s.artifact_bundles.update.not_been_called()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ArtifactBundleModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(artifact_bundle=self.ARTIFACT_BUNDLE))
    def test_should_upload_when_data_has_destination_path(self):
        self.resource.get_by_name.return_value = None
        self.resource.upload_bundle_from_file.return_value = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.resource.data = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_UPLOAD)

        ArtifactBundleModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_UPLOADED,
            ansible_facts=dict(artifact_bundle=DICT_DEFAULT_ARTIFACT_BUNDLE))
    def test_should_create_when_resource_not_exist(self):
        self.resource.get_by_name.return_value = None
        self.resource.create.return_value = self.resource
        self.resource.data = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_PRESENT)

        ArtifactBundleModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_CREATED,
            ansible_facts=dict(artifact_bundle=DICT_DEFAULT_ARTIFACT_BUNDLE))
示例#14
0
    def test_delete_artifact_bundle(self):
        self.resource.get_by.return_value = [self.ARTIFACT_BUNDLE]
        self.resource.delete.return_value = self.ARTIFACT_BUNDLE

        self.mock_ansible_module.params = self.TASK_REMOVE

        ArtifactBundleModule().run()

        self.resource.delete.assert_called_once_with(self.ARTIFACT_BUNDLE)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_DELETED,
        )
示例#15
0
    def test_upload_artifact_bundle_should_do_nothing_when_file_already_uploaded(self):
        self.i3s.artifact_bundles.get_by.return_value = [self.ARTIFACT_BUNDLE]
        self.i3s.artifact_bundles.upload_bundle_from_file.return_value = self.ARTIFACT_BUNDLE

        self.mock_ansible_module.params = self.TASK_UPLOAD

        ArtifactBundleModule().run()

        self.i3s.artifact_bundles.get_by.assert_called_once_with('name', 'uploaded_artifact')

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ArtifactBundleModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(artifact_bundle=self.ARTIFACT_BUNDLE))
    def test_should_update_when_data_has_modified_attributes(self):
        data_merged = DICT_DEFAULT_ARTIFACT_BUNDLE.copy()
        data_merged['newName'] = 'New Name'

        self.resource.data = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_RENAME)

        ArtifactBundleModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_UPDATED,
            ansible_facts=dict(artifact_bundle=DICT_DEFAULT_ARTIFACT_BUNDLE))
示例#17
0
    def test_upload_artifact_bundle_should_upload_when_file_not_uploaded_yet(self):
        self.i3s.artifact_bundles.get_by.return_value = []
        self.i3s.artifact_bundles.upload_bundle_from_file.return_value = self.ARTIFACT_BUNDLE

        self.mock_ansible_module.params = self.TASK_UPLOAD

        ArtifactBundleModule().run()

        self.i3s.artifact_bundles.upload_bundle_from_file.assert_called_once_with(
            self.TASK_UPLOAD['data']['localArtifactBundleFilePath'])

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_UPLOADED,
            ansible_facts=dict(artifact_bundle=self.ARTIFACT_BUNDLE))
示例#18
0
    def test_should_do_nothing_when_no_changes_provided(
            self, mock_resource_compare):
        mock_resource_compare.return_value = True

        self.resource.get_by.return_value = [self.ARTIFACT_BUNDLE]
        self.mock_ansible_module.params = self.TASK_UPDATE

        ArtifactBundleModule().run()

        self.resource.create.not_been_called()
        self.resource.update.not_been_called()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ArtifactBundleModule.MSG_ALREADY_PRESENT,
            ansible_facts=dict(artifact_bundle=self.ARTIFACT_BUNDLE))
示例#19
0
    def test_upload_backup_artifact_bundle(self):
        self.i3s.artifact_bundles.get_by.return_value = []
        self.i3s.artifact_bundles.upload_backup_bundle_from_file.return_value = self.DEPLOYMENT_GROUP

        self.mock_ansible_module.params = self.TASK_BACKUP_UPLOAD

        ArtifactBundleModule().run()

        self.i3s.artifact_bundles.upload_backup_bundle_from_file.assert_called_once_with(
            self.TASK_BACKUP_UPLOAD['data']['localBackupArtifactBundleFilePath'],
            self.TASK_BACKUP_UPLOAD['data']['deploymentGroupURI'])

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_BACKUP_UPLOADED,
            ansible_facts=dict(artifact_bundle_deployment_group=self.DEPLOYMENT_GROUP))
    def test_should_extract_backup(self):
        self.resource.data = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.resource.get_all_backups.return_value = [
            DICT_DEFAULT_ARTIFACT_BUNDLE
        ]
        self.resource.get_backup.return_value = self.resource
        self.resource.extract_backup.return_value = DICT_DEFAULT_ARTIFACT_BUNDLE
        self.mock_ansible_module.params = yaml.load(
            YAML_ARTIFACT_BUNDLE_BACKUP_EXTRACT)

        ArtifactBundleModule().run()

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_BACKUP_EXTRACTED,
            ansible_facts=dict(
                artifact_bundle_deployment_group=DICT_DEFAULT_ARTIFACT_BUNDLE))
示例#21
0
    def test_create_backup_artifact_bundle(self):
        artifact_bundle = self.TASK_CREATE['data']
        artifact_bundle['uri'] = '/rest/artifact-bundles/1'

        self.i3s.artifact_bundles.create_backup.return_value = self.DEPLOYMENT_GROUP

        self.mock_ansible_module.params = self.TASK_CREATE_BACKUP

        ArtifactBundleModule().run()

        self.i3s.artifact_bundles.create_backup.assert_called_once_with(
            self.TASK_CREATE_BACKUP['data'])

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ArtifactBundleModule.MSG_BACKUP_CREATED,
            ansible_facts=dict(artifact_bundle_deployment_group=self.DEPLOYMENT_GROUP))
示例#22
0
    def test_update_artifact_bundle_by_newname(self):
        artifact_bundle_updated = deepcopy(self.ARTIFACT_BUNDLE)
        artifact_bundle_updated['name'] = 'Artifact Bundle Updated'

        self.resource.get_by.side_effect = [None, [self.ARTIFACT_BUNDLE]]
        self.resource.update.return_value = artifact_bundle_updated

        self.mock_ansible_module.params = self.TASK_UPDATE

        ArtifactBundleModule().run()

        self.resource.update.assert_called_once_with(artifact_bundle_updated)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_UPDATED,
            ansible_facts=dict(artifact_bundle=artifact_bundle_updated))
示例#23
0
    def test_extract_artifact_bundle(self):
        artifact_bundle = self.TASK_CREATE['data']
        artifact_bundle['uri'] = '/rest/artifact-bundles/1'

        self.i3s.artifact_bundles.get_by.return_value = [artifact_bundle]

        self.i3s.artifact_bundles.extract_bundle.return_value = artifact_bundle

        self.mock_ansible_module.params = self.TASK_EXTRACT

        ArtifactBundleModule().run()

        self.i3s.artifact_bundles.extract_bundle.assert_called_once_with(artifact_bundle)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_EXTRACTED,
            ansible_facts=dict(artifact_bundle=artifact_bundle))
示例#24
0
    def test_download_artifact_bundle(self):
        artifact_bundle = self.TASK_CREATE['data']
        artifact_bundle['uri'] = '/rest/artifact-bundles/1'

        self.i3s.artifact_bundles.get_by.return_value = [artifact_bundle]

        self.mock_ansible_module.params = self.TASK_DOWNLOAD

        ArtifactBundleModule().run()

        download_file = self.TASK_DOWNLOAD['data']['destinationFilePath']
        uri = artifact_bundle['uri']

        self.i3s.artifact_bundles.download_artifact_bundle.assert_called_once_with(uri, download_file)

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=False,
            msg=ArtifactBundleModule.MSG_DOWNLOADED,
            ansible_facts={})
示例#25
0
    def test_backup_extract_artifact_bundle(self):
        artifact_bundle = self.TASK_CREATE['data']
        artifact_bundle['uri'] = '/rest/artifact-bundles/1'

        self.resource.get_by.return_value = [artifact_bundle]

        self.resource.extract_backup_bundle.return_value = self.DEPLOYMENT_GROUP

        self.mock_ansible_module.params = self.TASK_BACKUP_EXTRACT

        ArtifactBundleModule().run()

        self.resource.extract_backup_bundle.assert_called_once_with(
            self.TASK_CREATE_BACKUP['data'])

        self.mock_ansible_module.exit_json.assert_called_once_with(
            changed=True,
            msg=ArtifactBundleModule.MSG_BACKUP_EXTRACTED,
            ansible_facts=dict(
                artifact_bundle_deployment_group=self.DEPLOYMENT_GROUP))