コード例 #1
0
    def test_exception_unassign_member(self):
        set_module_args(args={
            'id': 'user-id',
            'type': 'User',
            'parent_id': 'group-id',
            'parent_type': 'Group',
            'state': 'absent'
        })

        def users_get(self, filter=None, order_by=None, group_by=None, page=None, page_size=None, query_parameters=None, commit=True,
                      callback=None, **kwargs):
            group_by = [] if group_by is None else group_by

            return [vsdk.NUUser(id='user-id'), vsdk.NUUser(id='user-id-2')]

        def group_assign(self, objects, nurest_object_type, callback=None, commit=True, **kwargs):
            raise BambouHTTPError(MockNuageConnection(status_code='500', reason='Server exception', errors={'description': 'Unable to remove member'}))

        with self.assertRaises(AnsibleFailJson) as exc:
            with patch('vspk.v5_0.fetchers.NUUsersFetcher.get', users_get):
                with patch('vspk.v5_0.NUGroup.assign', new=group_assign):
                    nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "Unable to remove entity as a member: [HTTP 500(Server exception)] {'description': 'Unable to remove member'}")
コード例 #2
0
    def test_state_present_children_update(self):
        set_module_args(args={
            'type': 'Enterprise',
            'state': 'present',
            'properties': {
                'name': 'test-enterprise'
            },
            'children': [
                {
                    'id': 'user-id',
                    'type': 'User',
                    'match_filter': 'userName == "johndoe"',
                    'properties': {
                        'user_name': 'johndoe-changed'
                    }
                }
            ]
        })

        with self.assertRaises(AnsibleExitJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertEqual(result['changed'], True)
        self.assertEqual(len(result['entities']), 2)
コード例 #3
0
    def test_state_present_children_create(self):
        set_module_args(args={
            'type': 'Enterprise',
            'state': 'present',
            'properties': {
                'name': 'test-enterprise-create'
            },
            'children': [
                {
                    'type': 'User',
                    'properties': {
                        'user_name': 'johndoe-new'
                    }
                }
            ]
        })

        def users_get(self, filter=None, order_by=None, group_by=None, page=None, page_size=None, query_parameters=None, commit=True,
                      callback=None, **kwargs):
            group_by = [] if group_by is None else group_by

            return []

        with self.assertRaises(AnsibleExitJson) as exc:
            with patch('vspk.v5_0.fetchers.NUUsersFetcher.get', users_get):
                nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['changed'])
        self.assertEqual(len(result['entities']), 2)
コード例 #4
0
    def test_fail_children_parent(self):
        set_module_args(args={
            'id': 'group-id',
            'type': 'Group',
            'state': 'present',
            'children': [
                {
                    'type': 'User',
                    'properties': {
                        'name': 'test-user'
                    }
                }
            ]
        })

        def users_get_first(self, filter=None, order_by=None, group_by=None, page=None, page_size=None, query_parameters=None, commit=True,
                            callback=None, **kwargs):
            group_by = [] if group_by is None else group_by

            return None

        with self.assertRaises(AnsibleFailJson) as exc:
            with patch('vspk.v5_0.fetchers.NUUsersFetcher.get_first', users_get_first):
                nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], 'Trying to assign a child that does not exist')
コード例 #5
0
    def test_certificate_auth(self):
        set_module_args(
            args={
                'type': 'Enterprise',
                'state': 'present',
                'properties': {
                    'name': 'test-enterprise'
                },
                'auth': {
                    'api_username': '******',
                    'api_certificate': '/dummy/location/certificate.pem',
                    'api_key': '/dummy/location/key.pem',
                    'api_enterprise': 'csp',
                    'api_url': 'https://localhost:8443',
                    'api_version': 'v5_0'
                }
            }
        )

        with self.assertRaises(AnsibleExitJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertFalse(result['changed'])
        self.assertEqual(len(result['entities']), 1)
        self.assertEqual(result['id'], 'enterprise-id')
        self.assertEqual(result['entities'][0]['name'], 'test-enterprise')
コード例 #6
0
    def test_input_require_on_off(self):
        set_module_args(args={
            'type': 'Enterprise'
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "one of the following is required: command,state")
コード例 #7
0
    def test_input_require_if_absent(self):
        set_module_args(args={
            'type': 'Enterprise',
            'state': 'absent',
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "state is absent but the following are missing: id,properties,match_filter")
コード例 #8
0
    def test_fail_type(self):
        set_module_args(args={
            'type': 'Unknown',
            'command': 'find'
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], 'Unrecognised type specified')
コード例 #9
0
    def test_fail_no_parent(self):
        set_module_args(args={
            'type': 'Group',
            'command': 'find'
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], 'No parent specified and root object is not a parent for the type')
コード例 #10
0
    def test_input_require_if_wait_for_job_id(self):
        set_module_args(args={
            'type': 'Job',
            'command': 'wait_for_job'
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "command is wait_for_job but the following are missing: id")
コード例 #11
0
    def test_input_exclusive(self):
        set_module_args(args={
            'type': 'Enterprise',
            'state': 'present',
            'command': 'find'
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "parameters are mutually exclusive: ['command', 'state']")
コード例 #12
0
    def test_input_require_both_parent_type(self):
        set_module_args(args={
            'type': 'User',
            'command': 'find',
            'parent_id': 'enterprise-id'
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "parameters are required together: ['parent_id', 'parent_type']")
コード例 #13
0
    def test_input_require_if_change_password_properties(self):
        set_module_args(args={
            'type': 'User',
            'command': 'change_password',
            'id': 'user-id'
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "command is change_password but the following are missing: properties")
コード例 #14
0
    def test_state_absent(self):
        set_module_args(args={
            'type': 'Enterprise',
            'state': 'absent',
            'properties': {
                'name': 'test-enterprise'
            }
        })

        with self.assertRaises(AnsibleExitJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['changed'])
コード例 #15
0
    def test_fail_parent_child(self):
        set_module_args(args={
            'type': 'Enterprise',
            'parent_id': 'user-id',
            'parent_type': 'User',
            'command': 'find'
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], 'Specified parent is not a valid parent for the specified type')
コード例 #16
0
    def test_command_get_csp_enterprise(self):
        set_module_args(args={
            'type': 'Enterprise',
            'command': 'get_csp_enterprise'
        })

        with self.assertRaises(AnsibleExitJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertFalse(result['changed'])
        self.assertEqual(len(result['entities']), 1)
        self.assertEqual(result['id'], 'enterprise-id')
        self.assertEqual(result['entities'][0]['name'], 'test-enterprise')
コード例 #17
0
    def test_state_present_existing_filter(self):
        set_module_args(args={
            'type': 'Enterprise',
            'state': 'present',
            'match_filter': 'name == "test-enterprise"'
        })

        with self.assertRaises(AnsibleExitJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertFalse(result['changed'])
        self.assertEqual(len(result['entities']), 1)
        self.assertEqual(result['id'], 'enterprise-id')
        self.assertEqual(result['entities'][0]['name'], 'test-enterprise')
コード例 #18
0
    def test_command_wait_for_job(self):
        set_module_args(args={
            'id': 'job-id',
            'type': 'Job',
            'command': 'wait_for_job',
        })

        with self.assertRaises(AnsibleExitJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertEqual(result['changed'], True)
        self.assertEqual(result['id'], 'job-id')
        self.assertEqual(result['entities'][0]['command'], 'EXPORT')
        self.assertEqual(result['entities'][0]['status'], 'SUCCESS')
コード例 #19
0
    def test_command_find_by_filter(self):
        set_module_args(args={
            'type': 'Enterprise',
            'command': 'find',
            'match_filter': 'name == "test%"'
        })

        with self.assertRaises(AnsibleExitJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertFalse(result['changed'])
        self.assertEqual(len(result['entities']), 2)
        self.assertEqual(result['entities'][0]['name'], 'test-enterprise')
        self.assertEqual(result['entities'][1]['name'], 'test-enterprise-2')
コード例 #20
0
    def test_fail_command_find(self):
        set_module_args(args={
            'type': 'Enterprise',
            'command': 'find',
            'properties': {
                'id': 'unknown-enterprise-id',
                'name': 'unkown-enterprise'
            }
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], 'Unable to find matching entries')
コード例 #21
0
    def test_fail_change_password_non_user(self):
        set_module_args(args={
            'id': 'group-id',
            'type': 'Group',
            'command': 'change_password',
            'properties': {
                'password': '******'
            }
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], 'Entity does not have a password property')
コード例 #22
0
    def test_exception_get_csp_enterprise(self):
        set_module_args(args={
            'type': 'Enterprise',
            'command': 'get_csp_enterprise'
        })

        def enterprise_failed_fetch(self, callback=None, **kwargs):
            raise BambouHTTPError(MockNuageConnection(status_code='404', reason='Not Found', errors={'description': 'Entity not found'}))

        with self.assertRaises(AnsibleFailJson) as exc:
            with patch('vspk.v5_0.NUEnterprise.fetch', enterprise_failed_fetch):
                nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "Unable to fetch CSP enterprise: [HTTP 404(Not Found)] {'description': 'Entity not found'}")
コード例 #23
0
    def test_state_present_create(self):
        set_module_args(args={
            'type': 'Enterprise',
            'state': 'present',
            'properties': {
                'name': 'test-enterprise-create'
            }
        })

        with self.assertRaises(AnsibleExitJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertEqual(result['changed'], True)
        self.assertEqual(len(result['entities']), 1)
        self.assertEqual(result['id'], 'enterprise-id-create')
        self.assertEqual(result['entities'][0]['name'], 'test-enterprise-create')
コード例 #24
0
    def test_exception_session(self):
        set_module_args(args={
            'id': 'enterprise-id',
            'type': 'Enterprise',
            'command': 'find'
        })

        def failed_session_start(self):
            raise BambouHTTPError(MockNuageConnection(status_code='401', reason='Unauthorized', errors={}))

        with self.assertRaises(AnsibleFailJson) as exc:
            with patch('vspk.v5_0.NUVSDSession.start', new=failed_session_start):
                nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], 'Unable to connect to the API URL with given username, password and enterprise: [HTTP 401(Unauthorized)] {}')
コード例 #25
0
    def test_exception_delete_entity(self):
        set_module_args(args={
            'id': 'enterprise-id',
            'type': 'Enterprise',
            'state': 'absent'
        })

        def enterprise_delete(self, response_choice=1, callback=None, **kwargs):
            raise BambouHTTPError(MockNuageConnection(status_code='500', reason='Server exception', errors={'description': 'Unable to delete entity'}))

        with self.assertRaises(AnsibleFailJson) as exc:
            with patch('vspk.v5_0.NUEnterprise.delete', enterprise_delete):
                nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "Unable to delete entity: [HTTP 500(Server exception)] {'description': 'Unable to delete entity'}")
コード例 #26
0
    def test_exception_find_entity_id(self):
        set_module_args(args={
            'id': 'enterprise-id',
            'type': 'Enterprise',
            'state': 'present'
        })

        def enterprise_failed_fetch(self, callback=None, **kwargs):
            raise BambouHTTPError(MockNuageConnection(status_code='404', reason='Not Found', errors={'description': 'Entity not found'}))

        with self.assertRaises(AnsibleFailJson) as exc:
            with patch('vspk.v5_0.NUEnterprise.fetch', enterprise_failed_fetch):
                nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "Failed to fetch the specified entity by ID: [HTTP 404(Not Found)] {'description': 'Entity not found'}")
コード例 #27
0
    def test_fail_has_changed(self):
        set_module_args(args={
            'id': 'user-id',
            'type': 'User',
            'state': 'present',
            'properties': {
                'user_name': 'changed-user',
                'fake': 'invalid-property',
                'password': '******'
            }
        })

        with self.assertRaises(AnsibleFailJson) as exc:
            nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], 'Property fake is not valid for this type of entity')
コード例 #28
0
    def test_exception_find_parent(self):
        set_module_args(args={
            'type': 'User',
            'parent_id': 'group-id',
            'parent_type': 'Group',
            'command': 'find'
        })

        def group_failed_fetch(self, callback=None, **kwargs):
            raise BambouHTTPError(MockNuageConnection(status_code='404', reason='Not Found', errors={'description': 'Entity not found'}))

        with self.assertRaises(AnsibleFailJson) as exc:
            with patch('vspk.v5_0.NUGroup.fetch', group_failed_fetch):
                nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "Failed to fetch the specified parent: [HTTP 404(Not Found)] {'description': 'Entity not found'}")
コード例 #29
0
    def test_exception_create_entity(self):
        set_module_args(args={
            'type': 'Enterprise',
            'state': 'present',
            'properties': {
                'name': 'test-enterprise-create'
            }
        })

        def me_create_child(self, nurest_object, response_choice=None, callback=None, commit=True, **kwargs):
            raise BambouHTTPError(MockNuageConnection(status_code='500', reason='Server exception', errors={'description': 'Unable to create entity'}))

        with self.assertRaises(AnsibleFailJson) as exc:
            with patch('vspk.v5_0.NUMe.create_child', me_create_child):
                nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertTrue(result['failed'])
        self.assertEqual(result['msg'], "Unable to create entity: [HTTP 500(Server exception)] {'description': 'Unable to create entity'}")
コード例 #30
0
    def test_exception_find_entity_property(self):
        set_module_args(args={
            'type': 'Enterprise',
            'match_filter': 'name == "enterprise-id"',
            'state': 'absent'
        })

        def enterprises_failed_get_first(self, filter=None, order_by=None, group_by=None, page=None, page_size=None, query_parameters=None, commit=True,
                                         callback=None, **kwargs):
            group_by = [] if group_by is None else group_by

            raise BambouHTTPError(MockNuageConnection(status_code='404', reason='Not Found', errors={'description': 'Entity not found'}))

        with self.assertRaises(AnsibleExitJson) as exc:
            with patch('vspk.v5_0.fetchers.NUEnterprisesFetcher.get_first', enterprises_failed_get_first):
                nuage_vspk.main()

        result = exc.exception.args[0]

        self.assertFalse(result['changed'])