def test_user_account_info(self):
        self.cluster_db = self.env.create(
            release_kwargs={'version': 'mitaka-9.0'},
        )
        self.env.create_nodes_w_interfaces_count(
            1, 1,
            roles=['controller'],
            pending_addition=True,
            cluster_id=self.cluster_db.id
        )
        self.env.create_nodes_w_interfaces_count(
            1, 1,
            roles=['compute'],
            pending_addition=True,
            cluster_id=self.cluster_db.id
        )

        attributes = objects.Cluster.get_attributes(self.cluster_db)
        operator_user = attributes['editable']['operator_user']
        service_user = attributes['editable']['service_user']

        serialized_cluster = self.serializer.serialize(
            self.cluster_db, self.cluster_db.nodes)

        operator_user_keys = utils.get_lines(
            operator_user['authkeys']['value']
        )
        common_keys = settings.AUTHORIZED_KEYS

        operator_user_dict = {
            'name': operator_user['name']['value'],
            'password': operator_user['password']['value'],
            'homedir': operator_user['homedir']['value'],
            'sudo': utils.get_lines(operator_user['sudo']['value']),
            'ssh_keys': operator_user_keys + common_keys
        }
        service_user_dict = {
            'name': service_user['name']['value'],
            'password': service_user['password']['value'],
            'homedir': service_user['homedir']['value'],
            'sudo': utils.get_lines(service_user['sudo']['value']),
            'ssh_keys': common_keys
        }
        root_user_dict = {
            'name': 'root',
            'homedir': '/root',
            'password': service_user['root_password']['value'],
            'ssh_keys': common_keys
        }

        user_accounts = [operator_user_dict,
                         service_user_dict,
                         root_user_dict]

        for node in serialized_cluster['nodes']:
            self.assertEqual(
                node['ks_meta']['user_accounts'],
                user_accounts
            )
예제 #2
0
    def test_get_lines(self):
        empty = ""
        empty_multiline = "\n\n\n"
        non_empty = "abc\nfoo\nbar"
        mixed = "abc\n\nfoo\n\n\nbar"

        self.assertEqual(get_lines(empty), [])

        self.assertEqual(get_lines(empty_multiline), [])

        self.assertEqual(get_lines(non_empty), ['abc', 'foo', 'bar'])

        self.assertEqual(get_lines(mixed), ['abc', 'foo', 'bar'])
    def serialize_node(cls, cluster_attrs, node):
        serialized_node = super(ProvisioningSerializer90, cls).serialize_node(
            cluster_attrs, node)

        operator_user = cluster_attrs.get('operator_user')
        service_user = cluster_attrs.get('service_user')
        serialized_node['ks_meta']['user_accounts'] = []
        # Make sure that there are no empty strings as this might mess up
        # cloud init templates
        if operator_user:
            operator_user_sudo = utils.get_lines(operator_user['sudo'])
            operator_user_authkeys = utils.get_lines(operator_user['authkeys'])
            operator_user_dict = {
                'name': operator_user['name'],
                'password': operator_user['password'],
                'homedir': operator_user['homedir'],
                'sudo': operator_user_sudo,
                'ssh_keys': operator_user_authkeys + settings.AUTHORIZED_KEYS,
            }
            serialized_node['ks_meta']['user_accounts'].append(
                operator_user_dict)

        if service_user:
            service_user_sudo = utils.get_lines(service_user['sudo'])
            root_password = service_user['root_password']

            service_user_dict = {
                'name': service_user['name'],
                'homedir': service_user['homedir'],
                'sudo': service_user_sudo,
                'password': service_user['password'],
                'ssh_keys': settings.AUTHORIZED_KEYS
            }
            root_user_dict = {
                'name': 'root',
                'homedir': '/root',
                'password': root_password,
                'ssh_keys': settings.AUTHORIZED_KEYS
            }
            serialized_node['ks_meta']['user_accounts'].append(
                service_user_dict)
            serialized_node['ks_meta']['user_accounts'].append(root_user_dict)

        return serialized_node
예제 #4
0
    def serialize_node(cls, cluster_attrs, node):
        serialized_node = super(ProvisioningSerializer90,
                                cls).serialize_node(cluster_attrs, node)

        operator_user = cluster_attrs.get('operator_user')
        service_user = cluster_attrs.get('service_user')
        serialized_node['ks_meta']['user_accounts'] = []
        # Make sure that there are no empty strings as this might mess up
        # cloud init templates
        if operator_user:
            operator_user_sudo = utils.get_lines(operator_user['sudo'])
            operator_user_authkeys = utils.get_lines(operator_user['authkeys'])
            operator_user_dict = {
                'name': operator_user['name'],
                'password': operator_user['password'],
                'homedir': operator_user['homedir'],
                'sudo': operator_user_sudo,
                'ssh_keys': operator_user_authkeys + settings.AUTHORIZED_KEYS,
            }
            serialized_node['ks_meta']['user_accounts'].append(
                operator_user_dict)

        if service_user:
            service_user_sudo = utils.get_lines(service_user['sudo'])
            root_password = service_user['root_password']

            service_user_dict = {
                'name': service_user['name'],
                'homedir': service_user['homedir'],
                'sudo': service_user_sudo,
                'password': service_user['password'],
                'ssh_keys': settings.AUTHORIZED_KEYS
            }
            root_user_dict = {
                'name': 'root',
                'homedir': '/root',
                'password': root_password,
                'ssh_keys': settings.AUTHORIZED_KEYS
            }
            serialized_node['ks_meta']['user_accounts'].append(
                service_user_dict)
            serialized_node['ks_meta']['user_accounts'].append(root_user_dict)

        return serialized_node