Пример #1
0
    def test__set_ambari_credentials__admin_only(self, client):
        client.side_effect = self._get_test_request
        self.requests = []
        plugin = ap.AmbariPlugin()

        cluster_config_file = pkg.resource_string(
            version.version_info.package,
            'plugins/hdp/versions/version_1_3_2/resources/'
            'default-cluster.template')
        cluster_spec = cs.ClusterSpec(cluster_config_file)

        ambari_info = ap.AmbariInfo(TestHost('111.11.1111'), '8080', 'admin',
                                    'old-pwd')
        plugin._set_ambari_credentials(cluster_spec, ambari_info, '1.3.2')

        self.assertEqual(1, len(self.requests))
        request = self.requests[0]
        self.assertEqual('put', request.method)
        self.assertEqual('http://111.11.1111:8080/api/v1/users/admin',
                         request.url)
        self.assertEqual(
            '{"Users":{"roles":"admin","password":"******",'
            '"old_password":"******"} }', request.data)
        self.assertEqual(('admin', 'old-pwd'), request.auth)
        self.assertEqual('admin', ambari_info.user)
        self.assertEqual('admin', ambari_info.password)
Пример #2
0
    def test__set_ambari_credentials__admin_only(self):
        self.requests = []
        plugin = ap.AmbariPlugin()
        plugin._get_rest_request = self._get_test_request

        with open(
                os.path.join(os.path.realpath('../plugins'), 'hdp',
                             'resources', 'default-cluster.template'),
                'r') as f:
            cluster_spec = cs.ClusterSpec(f.read())

        ambari_info = ap.AmbariInfo(TestHost('111.11.1111'), '8080', 'admin',
                                    'old-pwd')
        plugin._set_ambari_credentials(cluster_spec, ambari_info)

        self.assertEqual(1, len(self.requests))
        request = self.requests[0]
        self.assertEqual('put', request.method)
        self.assertEqual('http://111.11.1111:8080/api/v1/users/admin',
                         request.url)
        self.assertEqual(
            '{"Users":{"roles":"admin,user","password":"******",'
            '"old_password":"******"} }', request.data)
        self.assertEqual(('admin', 'old-pwd'), request.auth)
        self.assertEqual('admin', ambari_info.user)
        self.assertEqual('admin', ambari_info.password)
Пример #3
0
    def test_update_ambari_info_credentials(self):
        plugin = ap.AmbariPlugin()

        cluster_config_file = pkg.resource_string(
            version.version_info.package,
            'plugins/hdp/versions/1_3_2/resources/default-cluster.template')
        cluster_spec = cs.ClusterSpec(cluster_config_file)

        ambari_info = ap.AmbariInfo(TestHost('111.11.1111'), '8080', 'admin',
                                    'old-pwd')
        plugin._update_ambari_info_credentials(cluster_spec, ambari_info)

        self.assertEqual('admin', ambari_info.user)
        self.assertEqual('admin', ambari_info.password)
Пример #4
0
    def test__set_ambari_credentials__new_user_with_admin(self, client):
        self.requests = []
        plugin = ap.AmbariPlugin()
        client.side_effect = self._get_test_request

        cluster_config_file = pkg.resource_string(
            version.version_info.package,
            'plugins/hdp/versions/version_1_3_2/resources/'
            'default-cluster.template')
        cluster_spec = cs.ClusterSpec(cluster_config_file)

        for service in cluster_spec.services:
            if service.name == 'AMBARI':
                new_user = cs.User('test', 'test_pw', ['user'])
                service.users.append(new_user)

        ambari_info = ap.AmbariInfo(TestHost('111.11.1111'), '8080', 'admin',
                                    'old-pwd')
        plugin._set_ambari_credentials(cluster_spec, ambari_info, '1.3.2')
        self.assertEqual(2, len(self.requests))

        request = self.requests[0]
        self.assertEqual('put', request.method)
        self.assertEqual('http://111.11.1111:8080/api/v1/users/admin',
                         request.url)
        self.assertEqual(
            '{"Users":{"roles":"admin","password":"******",'
            '"old_password":"******"} }', request.data)
        self.assertEqual(('admin', 'old-pwd'), request.auth)

        request = self.requests[1]
        self.assertEqual('post', request.method)
        self.assertEqual('http://111.11.1111:8080/api/v1/users/test',
                         request.url)
        self.assertEqual('{"Users":{"password":"******","roles":"user"} }',
                         request.data)
        self.assertEqual(('admin', 'admin'), request.auth)

        self.assertEqual('admin', ambari_info.user)
        self.assertEqual('admin', ambari_info.password)
Пример #5
0
    def test__set_ambari_credentials__new_user_with_admin(self):
        self.requests = []
        plugin = ap.AmbariPlugin()
        plugin._get_rest_request = self._get_test_request

        with open(
                os.path.join(os.path.realpath('../plugins'), 'hdp',
                             'resources', 'default-cluster.template'),
                'r') as f:
            cluster_spec = cs.ClusterSpec(f.read())

        for service in cluster_spec.services:
            if service.name == 'AMBARI':
                new_user = cs.User('test', 'test_pw', ['user'])
                service.users.append(new_user)

        ambari_info = ap.AmbariInfo(TestHost('111.11.1111'), '8080', 'admin',
                                    'old-pwd')
        plugin._set_ambari_credentials(cluster_spec, ambari_info)
        self.assertEqual(2, len(self.requests))

        request = self.requests[0]
        self.assertEqual('put', request.method)
        self.assertEqual('http://111.11.1111:8080/api/v1/users/admin',
                         request.url)
        self.assertEqual(
            '{"Users":{"roles":"admin,user","password":"******",'
            '"old_password":"******"} }', request.data)
        self.assertEqual(('admin', 'old-pwd'), request.auth)

        request = self.requests[1]
        self.assertEqual('post', request.method)
        self.assertEqual('http://111.11.1111:8080/api/v1/users/test',
                         request.url)
        self.assertEqual('{"Users":{"password":"******","roles":"user"} }',
                         request.data)
        self.assertEqual(('admin', 'admin'), request.auth)

        self.assertEqual('admin', ambari_info.user)
        self.assertEqual('admin', ambari_info.password)
Пример #6
0
    def test__set_ambari_credentials__no_admin_user(self, client):
        self.requests = []
        plugin = ap.AmbariPlugin()
        client.side_effect = self._get_test_request

        cluster_config_file = pkg.resource_string(
            version.version_info.package,
            'plugins/hdp/versions/1_3_2/resources/default-cluster.template')
        cluster_spec = cs.ClusterSpec(cluster_config_file)

        for service in cluster_spec.services:
            if service.name == 'AMBARI':
                user = service.users[0]
                user.name = 'test'
                user.password = '******'
                user.groups = ['user']

        ambari_info = ap.AmbariInfo(TestHost('111.11.1111'), '8080', 'admin',
                                    'old-pwd')
        self.assertRaises(
            ex.HadoopProvisionError,
            plugin._set_ambari_credentials(cluster_spec, ambari_info, '1.3.2'))
Пример #7
0
    def test__set_ambari_credentials__no_admin_user(self):
        self.requests = []
        plugin = ap.AmbariPlugin()
        plugin._get_rest_request = self._get_test_request

        with open(
                os.path.join(os.path.realpath('../plugins'), 'hdp',
                             'resources', 'default-cluster.template'),
                'r') as f:
            cluster_spec = cs.ClusterSpec(f.read())

        for service in cluster_spec.services:
            if service.name == 'AMBARI':
                user = service.users[0]
                user.name = 'test'
                user.password = '******'
                user.groups = ['user']

        ambari_info = ap.AmbariInfo(TestHost('111.11.1111'), '8080', 'admin',
                                    'old-pwd')
        self.assertRaises(
            ex.HadoopProvisionError,
            plugin._set_ambari_credentials(cluster_spec, ambari_info))