Example #1
0
    def test_running_install_hosts(self):
        """
        Test packstack.installer.run_setup.main

        This test effectivly runs all of the python code ran by
        packstack --install-hosts=127.0.0.1 --os-swift-install=y \
        --nagios-install=y

        It is a fairly wide net but boost code coverage of the packstack
        python code to about 85%, more finer grained tests should also be
        Added to target speficic test cases.

        Popen is replaced in PackstackTestCaseMixin so no actual commands get
        run on the host running the unit tests
        """
        # we need following to pass manage_epel(enabled=1) and
        # manage_rdo(havana-6.noarch\nenabled=0) functions
        fake = FakePopen()
        fake.stdout = 'havana-6.noarch\nenabled=0enabled=1'
        subprocess.Popen = fake

        # create a dummy public key
        dummy_public_key = os.path.join(self.tempdir, 'id_rsa.pub')
        with open(dummy_public_key, 'w') as dummy:
            dummy.write('ssh-rsa AAAAblablabla')

        # Save sys.argv and replace it with the args we want optparse to use
        orig_argv = sys.argv
        sys.argv = [
            'packstack',
            '--ssh-public-key=%s' % dummy_public_key,
            '--install-hosts=127.0.0.1', '--os-swift-install=y',
            '--nagios-install=y', '--use-epel=y'
        ]

        # There is no puppet logfile to validate, so replace
        # ospluginutils.validate_puppet_logfile with a mock function
        orig_validate_logfile = puppet.validate_logfile
        puppet.validate_logfile = lambda a: None
        puppet.scan_logfile = lambda a: []

        # If there is a error in a plugin sys.exit() gets called, this masks
        # the actual error that should be reported, so we replace it to
        # raise Exception, packstack logging gives a more infomrative error
        def raise_(ex):
            raise ex

        orig_sys_exit = sys.exit
        sys.exit = lambda a: raise_(Exception('Error during install-hosts'))

        try:
            run_setup.main()
        finally:
            sys.argv = orig_argv
            ospluginutils.validate_puppet_logfile = orig_validate_logfile
            sys.exit = orig_sys_exit
            try:
                shutil.rmtree(basedefs.VAR_DIR)
            except:
                pass
Example #2
0
    def test_running_install_hosts(self):
        """
        Test packstack.installer.run_setup.main

        This test effectivly runs all of the python code ran by
        packstack --install-hosts=127.0.0.1 --os-swift-install=y \
        --nagios-install=y

        It is a fairly wide net but boost code coverage of the packstack
        python code to about 85%, more finer grained tests should also be
        Added to target speficic test cases.

        Popen is replaced in PackstackTestCaseMixin so no actual commands get
        run on the host running the unit tests
        """
        # we need following to pass manage_epel(enabled=1) and
        # manage_rdo(havana-6.noarch\nenabled=0) functions
        fake = FakePopen()
        fake.stdout = 'havana-6.noarch\nenabled=0enabled=1'
        subprocess.Popen = fake

        # create a dummy public key
        dummy_public_key = os.path.join(self.tempdir, 'id_rsa.pub')
        with open(dummy_public_key, 'w') as dummy:
            dummy.write('ssh-rsa AAAAblablabla')

        # Save sys.argv and replace it with the args we want optparse to use
        orig_argv = sys.argv
        sys.argv = ['packstack', '--ssh-public-key=%s' % dummy_public_key,
                    '--install-hosts=127.0.0.1', '--os-swift-install=y',
                    '--nagios-install=y', '--use-epel=y']

        # There is no puppet logfile to validate, so replace
        # ospluginutils.validate_puppet_logfile with a mock function
        orig_validate_logfile = puppet.validate_logfile
        puppet.validate_logfile = lambda a: None
        puppet.scan_logfile = lambda a: []

        # If there is a error in a plugin sys.exit() gets called, this masks
        # the actual error that should be reported, so we replace it to
        # raise Exception, packstack logging gives a more infomrative error
        def raise_(ex):
            raise ex
        orig_sys_exit = sys.exit
        sys.exit = lambda a: raise_(Exception('Error during install-hosts'))

        try:
            run_setup.main()
        finally:
            sys.argv = orig_argv
            ospluginutils.validate_puppet_logfile = orig_validate_logfile
            sys.exit = orig_sys_exit
            try:
                shutil.rmtree(basedefs.VAR_DIR)
            except:
                pass
Example #3
0
    def test_running_install_hosts(self):
        """
        Test packstack.installer.run_setup.main

        This test effectivly runs all of the python code ran by
        packstack --install-hosts=127.0.0.1 --os-swift-install=y \
        --nagios-install=y

        It is a fairly wide net but boost code coverage of the packstack
        python code to about 85%, more finer grained tests should also be
        Added to target speficic test cases.

        Popen is replaced in PackstackTestCaseMixin so no actual commands get
        run on the host running the unit tests
        """

        subprocess.Popen = FakePopen
        FakePopen.register('cat /etc/resolv.conf | grep nameserver',
                           stdout='nameserver 127.0.0.1')

        # required by packstack.plugins.serverprep_949.mangage_rdo
        FakePopen.register(
            "rpm -q rdo-release "
            "--qf='%{version}-%{release}.%{arch}\n'",
            stdout='icehouse-2.noarch\n')
        FakePopen.register_as_script(
            'yum-config-manager --enable '
            'openstack-icehouse',
            stdout='[openstack-icehouse]\nenabled=1')

        # required by packstack.plugins.nova_300.gather_host_keys
        FakePopen.register('ssh-keyscan 127.0.0.1',
                           stdout='127.0.0.1 ssh-rsa hostkey-data')

        # create a dummy public key
        dummy_public_key = os.path.join(self.tempdir, 'id_rsa.pub')
        makefile(dummy_public_key, 'ssh-rsa AAAAblablabla')

        # create dummy keys for live migration mechanism
        makefile(
            os.path.join(basedefs.VAR_DIR, 'nova_migration_key'),
            '-----BEGIN RSA PRIVATE KEY-----\n'
            'keydata\n'
            '-----END RSA PRIVATE KEY-----\n')
        makefile(os.path.join(basedefs.VAR_DIR, 'nova_migration_key.pub'),
                 'ssh-rsa keydata')

        # Save sys.argv and replace it with the args we want optparse to use
        orig_argv = sys.argv
        sys.argv = [
            'packstack', '--debug',
            '--ssh-public-key=%s' % dummy_public_key,
            '--install-hosts=127.0.0.1', '--os-swift-install=y',
            '--nagios-install=y', '--use-epel=y'
        ]

        # There is no puppet logfile to validate, so replace
        # ospluginutils.validate_puppet_logfile with a mock function
        orig_validate_logfile = puppet.validate_logfile
        puppet.validate_logfile = lambda a: None
        puppet.scan_logfile = lambda a: []

        # If there is a error in a plugin sys.exit() gets called, this masks
        # the actual error that should be reported, so we replace it to
        # raise Exception, packstack logging gives a more infomrative error
        def raise_(ex):
            raise ex

        orig_sys_exit = sys.exit
        sys.exit = lambda a: raise_(Exception('Error during install-hosts'))

        try:
            run_setup.main()
        finally:
            sys.argv = orig_argv
            ospluginutils.validate_puppet_logfile = orig_validate_logfile
            sys.exit = orig_sys_exit
            try:
                shutil.rmtree(basedefs.VAR_DIR)
            except:
                pass
    def test_running_install_hosts(self):
        """
        Test packstack.installer.run_setup.main

        This test effectivly runs all of the python code ran by
        packstack --install-hosts=127.0.0.1 --os-swift-install=y \
        --nagios-install=y

        It is a fairly wide net but boost code coverage of the packstack
        python code to about 85%, more finer grained tests should also be
        Added to target speficic test cases.

        Popen is replaced in PackstackTestCaseMixin so no actual commands get
        run on the host running the unit tests
        """

        subprocess.Popen = FakePopen
        FakePopen.register('cat /etc/resolv.conf | grep nameserver',
                           stdout='nameserver 127.0.0.1')

        # required by packstack.plugins.serverprep_949.mangage_rdo
        FakePopen.register("rpm -q rdo-release "
                           "--qf='%{version}-%{release}.%{arch}\n'",
                           stdout='icehouse-2.noarch\n')
        FakePopen.register_as_script('yum-config-manager --enable '
                                     'openstack-icehouse',
                                     stdout='[openstack-icehouse]\nenabled=1')

        FakePopen.register_as_script(
            'facter -p',
            stdout='operatingsystem => Fedora\noperatingsystemmajrelease => 21'
        )

        # required by packstack.plugins.nova_300.gather_host_keys
        FakePopen.register('ssh-keyscan 127.0.0.1',
                           stdout='127.0.0.1 ssh-rsa hostkey-data')

        # create a dummy public key
        dummy_public_key = os.path.join(self.tempdir, 'id_rsa.pub')
        makefile(dummy_public_key, 'ssh-rsa AAAAblablabla')

        # create dummy keys for live migration mechanism
        makefile(os.path.join(basedefs.VAR_DIR, 'nova_migration_key'),
                 '-----BEGIN RSA PRIVATE KEY-----\n'
                 'keydata\n'
                 '-----END RSA PRIVATE KEY-----\n')
        makefile(os.path.join(basedefs.VAR_DIR, 'nova_migration_key.pub'),
                 'ssh-rsa keydata')

        # Save sys.argv and replace it with the args we want optparse to use
        orig_argv = sys.argv
        sys.argv = ['packstack', '--debug',
                    '--ssh-public-key=%s' % dummy_public_key,
                    '--install-hosts=127.0.0.1', '--os-swift-install=y',
                    '--nagios-install=y', '--use-epel=y']

        # There is no puppet logfile to validate, so replace
        # ospluginutils.validate_puppet_logfile with a mock function
        orig_validate_logfile = puppet.validate_logfile
        puppet.validate_logfile = lambda a: None
        puppet.scan_logfile = lambda a: []

        # If there is a error in a plugin sys.exit() gets called, this masks
        # the actual error that should be reported, so we replace it to
        # raise Exception, packstack logging gives a more infomrative error
        def raise_(ex):
            raise ex
        orig_sys_exit = sys.exit
        sys.exit = lambda a: raise_(Exception('Error during install-hosts'))

        try:
            run_setup.main()
        finally:
            sys.argv = orig_argv
            ospluginutils.validate_puppet_logfile = orig_validate_logfile
            sys.exit = orig_sys_exit
            try:
                shutil.rmtree(basedefs.VAR_DIR)
            except:
                pass