def test_uninstall_lost_host(self):
        self.setup_cluster(self.PA_ONLY_CLUSTER)
        pa_installer = PrestoadminInstaller(self)
        pa_installer.install()
        topology = {
            "coordinator":
            self.cluster.internal_slaves[0],
            "workers": [
                self.cluster.internal_master, self.cluster.internal_slaves[1],
                self.cluster.internal_slaves[2]
            ]
        }
        self.upload_topology(topology)
        self.installer.install()
        start_output = self.run_prestoadmin('server start')
        process_per_host = self.get_process_per_host(start_output.splitlines())
        self.assert_started(process_per_host)
        down_node = self.cluster.internal_slaves[0]
        self.cluster.stop_host(self.cluster.slaves[0])

        expected = self.down_node_connection_error(
            self.cluster.internal_slaves[0])
        cmd_output = self.run_prestoadmin('server uninstall')
        self.assertRegexpMatches(cmd_output, expected)
        process_per_active_host = []
        for host, pid in process_per_host:
            if host not in down_node:
                process_per_active_host.append((host, pid))
        self.assert_stopped(process_per_active_host)

        for container in [
                self.cluster.internal_master, self.cluster.internal_slaves[1],
                self.cluster.internal_slaves[2]
        ]:
            self.assert_uninstalled_dirs_removed(container)
    def test_uninstall_lost_host(self):
        self.setup_cluster(NoHadoopBareImageProvider(), self.PA_ONLY_CLUSTER)
        pa_installer = PrestoadminInstaller(self)
        pa_installer.install()
        topology = {"coordinator": self.cluster.internal_slaves[0],
                    "workers": [self.cluster.internal_master,
                                self.cluster.internal_slaves[1],
                                self.cluster.internal_slaves[2]]}
        self.upload_topology(topology)
        self.installer.install()
        start_output = self.run_prestoadmin('server start')
        process_per_host = self.get_process_per_host(start_output.splitlines())
        self.assert_started(process_per_host)
        down_node = self.cluster.internal_slaves[0]
        self.cluster.stop_host(
            self.cluster.slaves[0])

        expected = self.down_node_connection_error(
            self.cluster.internal_slaves[0])
        cmd_output = self.run_prestoadmin('server uninstall',
                                          raise_error=False)
        self.assertRegexpMatches(cmd_output, expected)
        process_per_active_host = []
        for host, pid in process_per_host:
            if host not in down_node:
                process_per_active_host.append((host, pid))
        self.assert_stopped(process_per_active_host)

        for container in [self.cluster.internal_master,
                          self.cluster.internal_slaves[1],
                          self.cluster.internal_slaves[2]]:
            self.assert_uninstalled_dirs_removed(container)
예제 #3
0
class TestInstaller(BaseProductTestCase):

    def setUp(self):
        super(TestInstaller, self).setUp()
        self.centos_container = \
            self.__create_and_start_single_centos_container()
        self.pa_installer = PrestoadminInstaller(self)

    def tearDown(self):
        super(TestInstaller, self).tearDown()
        self.centos_container.tear_down()

    @attr('smoketest')
    @docker_only
    def test_online_installer(self):
        self.pa_installer._build_installer_in_docker(self.centos_container,
                                                     online_installer=True,
                                                     unique=True)
        self.__verify_third_party_dir(False)
        self.pa_installer.install(
            dist_dir=self.centos_container.get_dist_dir(unique=True))
        self.run_prestoadmin('--help', raise_error=True,
                             cluster=self.centos_container)

    @attr('smoketest')
    @docker_only
    def test_offline_installer(self):
        self.pa_installer._build_installer_in_docker(
            self.centos_container, online_installer=False, unique=True)
        self.__verify_third_party_dir(True)
        self.centos_container.exec_cmd_on_host(
            self.centos_container.master, 'ifdown eth0')
        self.pa_installer.install(
            dist_dir=self.centos_container.get_dist_dir(unique=True))
        self.run_prestoadmin('--help', raise_error=True,
                             cluster=self.centos_container)

    def __create_and_start_single_centos_container(self):
        centos_container = DockerCluster(
            'master', [], DEFAULT_LOCAL_MOUNT_POINT,
            DEFAULT_DOCKER_MOUNT_POINT)
        # we can't assume that another test has created the image
        centos_container.create_image(
            BASE_TD_DOCKERFILE_DIR,
            BASE_TD_IMAGE_NAME,
            BASE_IMAGE_NAME
        )
        centos_container.start_containers(
            BASE_TD_IMAGE_NAME,
            cap_add=['NET_ADMIN']
        )
        return centos_container

    def __verify_third_party_dir(self, is_third_party_present):
        matches = fnmatch.filter(
            os.listdir(self.centos_container.get_dist_dir(unique=True)),
            'prestoadmin-*.tar.bz2')
        if len(matches) > 1:
            raise RuntimeError(
                'More than one archive found in the dist directory ' +
                ' '.join(matches)
            )
        cmd_to_run = ['tar', '-tf',
                      os.path.join(
                          self.centos_container.get_dist_dir(unique=True),
                          matches[0])
                      ]
        popen_obj = subprocess.Popen(cmd_to_run,
                                     cwd=main_dir, stdout=subprocess.PIPE)
        retcode = popen_obj.returncode
        if retcode:
            raise RuntimeError('Non zero return code when executing ' +
                               ' '.join(cmd_to_run))
        stdout = popen_obj.communicate()[0]
        match = re.search('/third-party/', stdout)
        if is_third_party_present and match is None:
            raise RuntimeError('Expected to have an offline installer with '
                               'a third-party directory. Found no '
                               'third-party directory in the installer '
                               'archive.')
        elif not is_third_party_present and match:
            raise RuntimeError('Expected to have an online installer with no '
                               'third-party directory. Found a third-party '
                               'directory in the installer archive.')
예제 #4
0
class TestInstaller(BaseProductTestCase):
    def setUp(self):
        super(TestInstaller, self).setUp()
        self.setup_cluster(NoHadoopBareImageProvider, STANDALONE_BARE_CLUSTER)
        self.centos_container = \
            self.__create_and_start_single_centos_container()
        self.pa_installer = PrestoadminInstaller(self)

    def tearDown(self):
        super(TestInstaller, self).tearDown()
        self.centos_container.tear_down()

    @attr('smoketest')
    def test_online_installer(self):
        self.pa_installer._build_installer_in_docker(self.centos_container,
                                                     online_installer=True,
                                                     unique=True)
        self.__verify_third_party_dir(False)
        self.pa_installer.install(dist_dir=self.centos_container.get_dist_dir(
            unique=True))
        self.run_prestoadmin('--help', raise_error=True)

    @attr('smoketest', 'offline_installer')
    @docker_only
    def test_offline_installer(self):
        self.pa_installer._build_installer_in_docker(self.centos_container,
                                                     online_installer=False,
                                                     unique=True)
        self.__verify_third_party_dir(True)
        self.centos_container.exec_cmd_on_host(
            # IMPORTANT: ifdown eth0 fails silently without taking the
            # interface down if the NET_ADMIN capability isn't set for the
            # container. ifconfig eth0 down accomplishes the same thing, but
            # results in a failure if it fails.
            self.centos_container.master,
            'ifconfig eth0 down')
        self.pa_installer.install(dist_dir=self.centos_container.get_dist_dir(
            unique=True))
        self.run_prestoadmin('--help', raise_error=True)

    def __create_and_start_single_centos_container(self):
        cluster_type = 'installer_tester'
        bare_image_provider = NoHadoopBareImageProvider(BASE_IMAGES_TAG)
        centos_container, bare_cluster = DockerCluster.start_cluster(
            bare_image_provider,
            cluster_type,
            'master', [],
            cap_add=['NET_ADMIN'])

        if bare_cluster:
            centos_container.commit_images(bare_image_provider, cluster_type)

        return centos_container

    def __verify_third_party_dir(self, is_third_party_present):
        matches = fnmatch.filter(
            os.listdir(self.centos_container.get_dist_dir(unique=True)),
            'prestoadmin-*.tar.gz')
        if len(matches) > 1:
            raise RuntimeError(
                'More than one archive found in the dist directory ' +
                ' '.join(matches))
        cmd_to_run = [
            'tar', '-tf',
            os.path.join(self.centos_container.get_dist_dir(unique=True),
                         matches[0])
        ]
        popen_obj = subprocess.Popen(cmd_to_run,
                                     cwd=main_dir,
                                     stdout=subprocess.PIPE)
        retcode = popen_obj.returncode
        if retcode:
            raise RuntimeError('Non zero return code when executing ' +
                               ' '.join(cmd_to_run))
        stdout = popen_obj.communicate()[0]
        match = re.search('/third-party/', stdout)
        if is_third_party_present and match is None:
            raise RuntimeError('Expected to have an offline installer with '
                               'a third-party directory. Found no '
                               'third-party directory in the installer '
                               'archive.')
        elif not is_third_party_present and match:
            raise RuntimeError('Expected to have an online installer with no '
                               'third-party directory. Found a third-party '
                               'directory in the installer archive.')
예제 #5
0
class TestInstaller(BaseProductTestCase):
    def setUp(self):
        super(TestInstaller, self).setUp()
        self.centos_container = \
            self.__create_and_start_single_centos_container()
        self.pa_installer = PrestoadminInstaller(self)

    def tearDown(self):
        super(TestInstaller, self).tearDown()
        self.centos_container.tear_down()

    @attr('smoketest')
    @docker_only
    def test_online_installer(self):
        self.pa_installer._build_installer_in_docker(self.centos_container,
                                                     online_installer=True,
                                                     unique=True)
        self.__verify_third_party_dir(False)
        self.pa_installer.install(dist_dir=self.centos_container.get_dist_dir(
            unique=True))
        self.run_prestoadmin('--help',
                             raise_error=True,
                             cluster=self.centos_container)

    @attr('smoketest')
    @docker_only
    def test_offline_installer(self):
        self.pa_installer._build_installer_in_docker(self.centos_container,
                                                     online_installer=False,
                                                     unique=True)
        self.__verify_third_party_dir(True)
        self.centos_container.exec_cmd_on_host(self.centos_container.master,
                                               'ifdown eth0')
        self.pa_installer.install(dist_dir=self.centos_container.get_dist_dir(
            unique=True))
        self.run_prestoadmin('--help',
                             raise_error=True,
                             cluster=self.centos_container)

    def __create_and_start_single_centos_container(self):
        centos_container = DockerCluster('master', [],
                                         DEFAULT_LOCAL_MOUNT_POINT,
                                         DEFAULT_DOCKER_MOUNT_POINT)
        # we can't assume that another test has created the image
        centos_container.create_image(BASE_TD_DOCKERFILE_DIR,
                                      BASE_TD_IMAGE_NAME, BASE_IMAGE_NAME)
        centos_container.start_containers(BASE_TD_IMAGE_NAME,
                                          cap_add=['NET_ADMIN'])
        return centos_container

    def __verify_third_party_dir(self, is_third_party_present):
        matches = fnmatch.filter(
            os.listdir(self.centos_container.get_dist_dir(unique=True)),
            'prestoadmin-*.tar.bz2')
        if len(matches) > 1:
            raise RuntimeError(
                'More than one archive found in the dist directory ' +
                ' '.join(matches))
        cmd_to_run = [
            'tar', '-tf',
            os.path.join(self.centos_container.get_dist_dir(unique=True),
                         matches[0])
        ]
        popen_obj = subprocess.Popen(cmd_to_run,
                                     cwd=main_dir,
                                     stdout=subprocess.PIPE)
        retcode = popen_obj.returncode
        if retcode:
            raise RuntimeError('Non zero return code when executing ' +
                               ' '.join(cmd_to_run))
        stdout = popen_obj.communicate()[0]
        match = re.search('/third-party/', stdout)
        if is_third_party_present and match is None:
            raise RuntimeError('Expected to have an offline installer with '
                               'a third-party directory. Found no '
                               'third-party directory in the installer '
                               'archive.')
        elif not is_third_party_present and match:
            raise RuntimeError('Expected to have an online installer with no '
                               'third-party directory. Found a third-party '
                               'directory in the installer archive.')
예제 #6
0
class TestInstaller(BaseProductTestCase):

    def setUp(self):
        super(TestInstaller, self).setUp()
        self.setup_cluster(NoHadoopBareImageProvider, STANDALONE_BARE_CLUSTER)
        self.centos_container = \
            self.__create_and_start_single_centos_container()
        self.pa_installer = PrestoadminInstaller(self)

    def tearDown(self):
        super(TestInstaller, self).tearDown()
        self.centos_container.tear_down()

    @attr('smoketest')
    def test_online_installer(self):
        self.pa_installer._build_installer_in_docker(self.centos_container,
                                                     online_installer=True,
                                                     unique=True)
        self.__verify_third_party_dir(False)
        self.pa_installer.install(
            dist_dir=self.centos_container.get_dist_dir(unique=True))
        self.run_prestoadmin('--help', raise_error=True)

    @attr('smoketest', 'offline_installer')
    @docker_only
    def test_offline_installer(self):
        self.pa_installer._build_installer_in_docker(
            self.centos_container, online_installer=False, unique=True)
        self.__verify_third_party_dir(True)
        self.centos_container.exec_cmd_on_host(
            # IMPORTANT: ifdown eth0 fails silently without taking the
            # interface down if the NET_ADMIN capability isn't set for the
            # container. ifconfig eth0 down accomplishes the same thing, but
            # results in a failure if it fails.
            self.centos_container.master, 'ifconfig eth0 down')
        self.pa_installer.install(
            dist_dir=self.centos_container.get_dist_dir(unique=True))
        self.run_prestoadmin('--help', raise_error=True)

    def __create_and_start_single_centos_container(self):
        cluster_type = 'installer_tester'
        bare_image_provider = NoHadoopBareImageProvider(BASE_IMAGES_TAG)
        centos_container, bare_cluster = DockerCluster.start_cluster(
            bare_image_provider, cluster_type, 'master', [],
            cap_add=['NET_ADMIN'])

        if bare_cluster:
            centos_container.commit_images(bare_image_provider, cluster_type)

        return centos_container

    def __verify_third_party_dir(self, is_third_party_present):
        matches = fnmatch.filter(
            os.listdir(self.centos_container.get_dist_dir(unique=True)),
            'prestoadmin-*.tar.bz2')
        if len(matches) > 1:
            raise RuntimeError(
                'More than one archive found in the dist directory ' +
                ' '.join(matches)
            )
        cmd_to_run = ['tar', '-tf',
                      os.path.join(
                          self.centos_container.get_dist_dir(unique=True),
                          matches[0])
                      ]
        popen_obj = subprocess.Popen(cmd_to_run,
                                     cwd=main_dir, stdout=subprocess.PIPE)
        retcode = popen_obj.returncode
        if retcode:
            raise RuntimeError('Non zero return code when executing ' +
                               ' '.join(cmd_to_run))
        stdout = popen_obj.communicate()[0]
        match = re.search('/third-party/', stdout)
        if is_third_party_present and match is None:
            raise RuntimeError('Expected to have an offline installer with '
                               'a third-party directory. Found no '
                               'third-party directory in the installer '
                               'archive.')
        elif not is_third_party_present and match:
            raise RuntimeError('Expected to have an online installer with no '
                               'third-party directory. Found a third-party '
                               'directory in the installer archive.')