def test_subscription_patch_update(self, *args):
        set_module_args(
            dict(subscription_id='s-xxxxxxxxxx',
                 patch=True,
                 configuration=dict(gslb_service=dict(custom_parameter=True))))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode)

        get_subscription_fake = load_fixture(
            'f5_cs_dnslb_subscription_app_update_default.json')
        get_user_fake = load_fixture('f5_cs_subscription_app_get_user.json')
        get_subscriptions_fake = load_fixture(
            'f5_cs_dnslb_subscriptions_get.json')
        connection = Mock()
        api_client = CloudservicesApi(connection)
        api_client.login = Mock()
        api_client.update_subscription = Mock(
            side_effect=self.update_subscription)
        api_client.get_subscription_by_id = Mock(
            return_value=get_subscription_fake)
        api_client.get_current_user = Mock(return_value=get_user_fake)
        api_client.get_subscriptions_by_type = Mock(
            return_value=get_subscriptions_fake)

        mm = ModuleManager(module=module, client=api_client)
        results = mm.exec_module()

        assert results['changed'] is True
        assert results['subscription_id'] == 's-xxxxxxxxxx'
    def test_subscription_suspend(self, *args):
        set_module_args(
            dict(
                subscription_id='s-xxxxxxxxxx',
                state='suspended',
            ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode)

        get_subscription_status = load_fixture(
            'f5_cs_subscription_app_suspend.json')
        get_user_fake = load_fixture('f5_cs_subscription_app_get_user.json')
        get_subscriptions_fake = load_fixture(
            'f5_cs_dnslb_subscriptions_get.json')
        connection = Mock()
        api_client = CloudservicesApi(connection)
        api_client.login = Mock()
        api_client.suspend_subscription = Mock()
        api_client.get_subscription_status = Mock(
            return_value=get_subscription_status)
        api_client.get_current_user = Mock(return_value=get_user_fake)
        api_client.get_subscriptions_by_type = Mock(
            return_value=get_subscriptions_fake)

        mm = ModuleManager(module=module, client=api_client)
        results = mm.exec_module()

        assert results['changed'] is True
        assert results['subscription_id'] == 's-xxxxxxxxxx'
        assert results['status'] == 'DISABLED'
示例#3
0
    def test_subscription_fetch(self, *args):
        set_module_args(dict(
            state='fetch',
            subscription_id='s-xxxxxxxxxx',
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode
        )

        get_subscription_fake = load_fixture('f5_cs_dnslb_subscription_app_fetch.json')
        connection = Mock()
        api_client = CloudservicesApi(connection)
        api_client.login = Mock()

        api_client.get_subscription_by_id = Mock(return_value=get_subscription_fake)

        mm = ModuleManager(module=module, client=api_client)
        results = mm.exec_module()

        assert results['changed'] is False
        assert results['account_id'] == 'a-xxxxxxxxxx'
        assert results['catalog_id'] == 'c-xxxxxxxxxx'
        assert results['subscription_id'] == 's-xxxxxxxxxx'
        assert results['service_instance_name'] == 'fqdn.demo.com'
        assert results['configuration']['gslb_service']['virtual_servers']['ipEndpoint_1']['address'] == '12.34.56.78'
        assert results['configuration']['gslb_service']['virtual_servers']['ipEndpoint_1']['display_name'] == 'endpoint_1'
        assert results['configuration']['gslb_service']['virtual_servers']['ipEndpoint_1']['monitor'] == 'none'
        assert results['configuration']['gslb_service']['virtual_servers']['ipEndpoint_1']['port'] == 80
        assert results['configuration']['gslb_service']['virtual_servers']['ipEndpoint_1']['virtual_server_type'] == 'cloud'
    def test_subscription_app_create(self, *args):
        set_module_args(
            dict(service_instance_name="fqdn.demo.com",
                 configuration=dict(
                     gslb_service=dict(zone="fqdn.demo.com",
                                       virtual_servers=dict(ipEndpoint_1=dict(
                                           address="12.34.56.78",
                                           display_name="endpoint_1",
                                           monitor="none",
                                           port=80,
                                           virtual_server_type="cloud"))))))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode)

        get_catalogs_fake = load_fixture(
            'f5_cs_subscription_app_get_catalogs.json')
        get_user_fake = load_fixture('f5_cs_subscription_app_get_user.json')
        get_subscriptions_fake = load_fixture(
            'f5_cs_dnslb_subscriptions_get_empty.json')
        get_subscription_status = load_fixture(
            'f5_cs_subscription_app_active.json')
        connection = Mock()
        api_client = CloudservicesApi(connection)
        api_client.login = Mock()

        api_client.get_catalogs = Mock(return_value=get_catalogs_fake)
        api_client.get_current_user = Mock(return_value=get_user_fake)
        api_client.create_subscription = Mock(
            side_effect=self.create_subscription)
        api_client.get_subscriptions_by_type = Mock(
            return_value=get_subscriptions_fake)
        api_client.get_subscription_status = Mock(
            return_value=get_subscription_status)
        api_client.activate_subscription = Mock()

        mm = ModuleManager(module=module, client=api_client)
        results = mm.exec_module()

        assert results['changed'] is True
        assert results['account_id'] == 'a-xxxxxxxxxx'
        assert results['subscription_id'] == 's-xxxxxxxxxx'
        assert results['service_instance_name'] == 'fqdn.demo.com'
        assert results['configuration']['gslb_service']['virtual_servers'][
            'ipEndpoint_1']['address'] == '12.34.56.78'
        assert results['configuration']['gslb_service']['virtual_servers'][
            'ipEndpoint_1']['display_name'] == 'endpoint_1'
        assert results['configuration']['gslb_service']['virtual_servers'][
            'ipEndpoint_1']['monitor'] == 'none'
        assert results['configuration']['gslb_service']['virtual_servers'][
            'ipEndpoint_1']['port'] == 80
        assert results['configuration']['gslb_service']['virtual_servers'][
            'ipEndpoint_1']['virtual_server_type'] == 'cloud'
示例#5
0
    def test_subscription_retire(self, *args):
        set_module_args(dict(
            state='absent',
            subscription_id='s-xxxxxxxxxx',
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode
        )

        connection = Mock()
        api_client = CloudservicesApi(connection)
        api_client.login = Mock()
        api_client.retire_subscription = Mock(side_effect=self.retire_subscription)

        mm = ModuleManager(module=module, client=api_client)
        results = mm.exec_module()

        assert results['changed'] is True
        assert results['status'] == 'RETIRED'
        assert results['subscription_id'] == 's-xxxxxxxxxx'
示例#6
0
    def test_subscription_activate(self, *args):
        set_module_args(dict(
            subscription_id='s-xxxxxxxxxx',
            state='active',
        ))

        module = AnsibleModule(
            argument_spec=self.spec.argument_spec,
            supports_check_mode=self.spec.supports_check_mode
        )

        get_subscription_status = load_fixture('f5_cs_dnslb_subscription_app_active.json')
        connection = Mock()
        api_client = CloudservicesApi(connection)
        api_client.login = Mock()
        api_client.activate_subscription = Mock()
        api_client.get_subscription_status = Mock(return_value=get_subscription_status)

        mm = ModuleManager(module=module, client=api_client)
        results = mm.exec_module()

        assert results['changed'] is True
        assert results['subscription_id'] == 's-xxxxxxxxxx'
        assert results['status'] == 'ACTIVE'