Пример #1
0
 def test_generate_etc_hosts(self):
     cluster = self._make_sample()
     ctx = context.ctx()
     idx = 0
     for ng in cluster.node_groups:
         for i in range(ng.count):
             idx += 1
             self.api.instance_add(ctx, ng, {
                 'instance_id': str(idx),
                 'instance_name': str(idx),
                 'internal_ip': str(idx),
             })
     cluster = self.api.cluster_get(ctx, cluster)
     with mock.patch("sahara.utils.openstack.base.url_for") as mock_url:
         mock_url.side_effect = ["http://keystone.local:1234/v13",
                                 "http://swift.local:5678/v42"]
         with mock.patch("socket.gethostbyname") as mock_get_host:
             mock_get_host.side_effect = ["1.2.3.4", "5.6.7.8"]
             value = cluster_utils.generate_etc_hosts(cluster)
     expected = ("127.0.0.1 localhost\n"
                 "1 1.novalocal 1\n"
                 "2 2.novalocal 2\n"
                 "3 3.novalocal 3\n"
                 "4 4.novalocal 4\n"
                 "1.2.3.4 keystone.local\n"
                 "5.6.7.8 swift.local\n")
     self.assertEqual(expected, value)
Пример #2
0
    def test_generate_etc_hosts(self, mock_url, mock_get_host,
                                mock_use_designate):
        cluster = self._make_sample()
        mock_use_designate.return_value = False
        ctx = context.ctx()
        idx = 0
        for ng in cluster.node_groups:
            for i in range(ng.count):
                idx += 1
                self.api.instance_add(
                    ctx, ng, {
                        'instance_id': str(idx),
                        'instance_name': str(idx),
                        'internal_ip': str(idx),
                    })
        cluster = self.api.cluster_get(ctx, cluster)

        mock_url.side_effect = [
            "http://keystone.local:1234/v13", "http://swift.local:5678/v42"
        ]
        mock_get_host.side_effect = ["1.2.3.4", "5.6.7.8"]

        value = cluster_utils.generate_etc_hosts(cluster)

        expected = ("127.0.0.1 localhost\n"
                    "1 1.novalocal 1\n"
                    "2 2.novalocal 2\n"
                    "3 3.novalocal 3\n"
                    "4 4.novalocal 4\n"
                    "1.2.3.4 keystone.local\n"
                    "5.6.7.8 swift.local\n")
        self.assertEqual(expected, value)
Пример #3
0
    def test_generate_etc_hosts(self, mock_url, mock_get_host,
                                mock_use_designate):
        cluster = self._make_sample()
        mock_use_designate.return_value = False
        ctx = context.ctx()
        idx = 0
        for ng in cluster.node_groups:
            for i in range(ng.count):
                idx += 1
                self.api.instance_add(ctx, ng, {
                    'instance_id': str(idx),
                    'instance_name': str(idx),
                    'internal_ip': str(idx),
                })
        cluster = self.api.cluster_get(ctx, cluster)

        mock_url.side_effect = ["http://keystone.local:1234/v13",
                                "http://swift.local:5678/v42"]
        mock_get_host.side_effect = ["1.2.3.4", "5.6.7.8"]

        value = cluster_utils.generate_etc_hosts(cluster)

        expected = ("127.0.0.1 localhost\n"
                    "1 1.novalocal 1\n"
                    "2 2.novalocal 2\n"
                    "3 3.novalocal 3\n"
                    "4 4.novalocal 4\n"
                    "1.2.3.4 keystone.local\n"
                    "5.6.7.8 swift.local\n")
        self.assertEqual(expected, value)
Пример #4
0
    def _configure_instance_etc_hosts(self, instance, cluster):
        LOG.debug('Configuring "/etc/hosts" of instance.')
        hosts_file = cluster_utils.generate_etc_hosts(cluster)
        with instance.remote() as r:
            r.write_file_to('etc-hosts', hosts_file)
            r.execute_command('sudo hostname %s' % instance.fqdn())
            r.execute_command('sudo mv etc-hosts /etc/hosts')

            r.execute_command('sudo usermod -s /bin/bash $USER')
Пример #5
0
    def _configure_instance_etc_hosts(self, instance, cluster):
        LOG.debug('Configuring "/etc/hosts" of instance.')
        hosts_file = cluster_utils.generate_etc_hosts(cluster)
        with instance.remote() as r:
            r.write_file_to('etc-hosts', hosts_file)
            r.execute_command('sudo hostname %s' % instance.fqdn())
            r.execute_command('sudo mv etc-hosts /etc/hosts')

            r.execute_command('sudo usermod -s /bin/bash $USER')
Пример #6
0
def _get_cluster_hosts_information(host, cluster):
    for clust in conductor.cluster_get_all(context.ctx()):
        if clust.id == cluster.id:
            continue

        for i in u.get_instances(clust):
            if i.instance_name == host:
                return cluster_utils.generate_etc_hosts(clust)

    return None
Пример #7
0
def _get_cluster_hosts_information(host, cluster):
    for clust in conductor.cluster_get_all(context.ctx()):
        if clust.id == cluster.id:
            continue

        for i in u.get_instances(clust):
            if i.instance_name == host:
                return cluster_utils.generate_etc_hosts(clust)

    return None
Пример #8
0
    def test_generate_etc_hosts_with_designate(self, mock_url, mock_get_host,
                                               mock_use_designate):
        cluster = self._make_sample()
        mock_use_designate.return_value = True
        mock_url.side_effect = ["http://keystone.local:1234/v13",
                                "http://swift.local:5678/v42"]
        mock_get_host.side_effect = ["1.2.3.4", "5.6.7.8"]

        value = cluster_utils.generate_etc_hosts(cluster)

        expected = ("127.0.0.1 localhost\n"
                    "1.2.3.4 keystone.local\n"
                    "5.6.7.8 swift.local\n")
        self.assertEqual(expected, value)
Пример #9
0
    def test_generate_etc_hosts_with_designate(self, mock_url, mock_get_host,
                                               mock_use_designate):
        cluster = self._make_sample()
        mock_use_designate.return_value = True
        mock_url.side_effect = ["http://keystone.local:1234/v13",
                                "http://swift.local:5678/v42"]
        mock_get_host.side_effect = ["1.2.3.4", "5.6.7.8"]

        value = cluster_utils.generate_etc_hosts(cluster)

        expected = ("127.0.0.1 localhost\n"
                    "1.2.3.4 keystone.local\n"
                    "5.6.7.8 swift.local\n")
        self.assertEqual(expected, value)
Пример #10
0
    def _configure_instances(self, cluster):
        """Configure active instances.

        * generate /etc/hosts
        * setup passwordless login
        * etc.
        """
        hosts_file = cluster_utils.generate_etc_hosts(cluster)
        cpo.add_provisioning_step(
            cluster.id, _("Configure instances"),
            cluster_utils.count_instances(cluster))

        with context.ThreadGroup() as tg:
            for node_group in cluster.node_groups:
                for instance in node_group.instances:
                    with context.set_current_instance_id(instance.instance_id):
                        tg.spawn(
                            "configure-instance-%s" % instance.instance_name,
                            self._configure_instance, instance, hosts_file)
Пример #11
0
 def test_generate_etc_hosts(self):
     cluster = self._make_sample()
     ctx = context.ctx()
     idx = 0
     for ng in cluster.node_groups:
         for i in range(ng.count):
             idx += 1
             self.api.instance_add(ctx, ng, {
                 'instance_id': str(idx),
                 'instance_name': str(idx),
                 'internal_ip': str(idx),
             })
     cluster = self.api.cluster_get(ctx, cluster)
     value = cluster_utils.generate_etc_hosts(cluster)
     expected = ("127.0.0.1 localhost\n"
                 "1 1.novalocal 1\n"
                 "2 2.novalocal 2\n"
                 "3 3.novalocal 3\n"
                 "4 4.novalocal 4\n")
     self.assertEqual(expected, value)