Пример #1
0
def execute(cmd, raise_error=True):
    """Executes a command in a subprocess.
    Returns a tuple of (exitcode, out, err), where out is the string output
    from stdout and err is the string output from stderr when
    executing the command.

    :param cmd: Command string to execute
    :param raise_error: If returncode is not 0 (success), then
                        raise a RuntimeError? Default: True)

    """

    env = os.environ.copy()

    # Make sure that we use the programs in the
    # current source directory's bin/ directory.
    env['PATH'] = tests.melange_bin_path() + ':' + env['PATH']
    process = subprocess.Popen(cmd,
                               shell=True,
                               stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
                               env=env)
    result = process.communicate()
    (out, err) = result
    exitcode = process.returncode
    if process.returncode != 0 and raise_error:
        msg = "Command %(cmd)s did not succeed. Returned an exit "\
              "code of %(exitcode)d."\
              "\n\nSTDOUT: %(out)s"\
              "\n\nSTDERR: %(err)s" % locals()
        raise RuntimeError(msg)
    return exitcode, out, err
Пример #2
0
def execute(cmd, raise_error=True):
    """Executes a command in a subprocess.
    Returns a tuple of (exitcode, out, err), where out is the string output
    from stdout and err is the string output from stderr when
    executing the command.

    :param cmd: Command string to execute
    :param raise_error: If returncode is not 0 (success), then
                        raise a RuntimeError? Default: True)

    """

    env = os.environ.copy()

    # Make sure that we use the programs in the
    # current source directory's bin/ directory.
    env['PATH'] = tests.melange_bin_path() + ':' + env['PATH']
    process = subprocess.Popen(cmd,
                               shell=True,
                               stdin=subprocess.PIPE,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE,
                               env=env)
    result = process.communicate()
    (out, err) = result
    exitcode = process.returncode
    if process.returncode != 0 and raise_error:
        msg = "Command %(cmd)s did not succeed. Returned an exit "\
              "code of %(exitcode)d."\
              "\n\nSTDOUT: %(out)s"\
              "\n\nSTDERR: %(err)s" % locals()
        raise RuntimeError(msg)
    return exitcode, out, err
Пример #3
0
    def test_deallocated_ips_get_deleted(self):
        block = factory_models.PublicIpBlockFactory()
        ip = factory_models.IpAddressFactory(ip_block_id=block.id)
        block.deallocate_ip(ip.address)

        days = config.Config.get('keep_deallocated_ips_for_days')
        self._push_back_deallocated_date(ip, days)

        script = tests.melange_bin_path('melange-delete-deallocated-ips')
        config_file = tests.test_config_file()
        functional.execute("{0} --config-file={1}".format(script, config_file))

        self.assertIsNone(models.IpAddress.get(ip.id))
Пример #4
0
    def test_deallocated_ips_get_deleted(self):
        block = factory_models.PublicIpBlockFactory()
        ip = factory_models.IpAddressFactory(ip_block_id=block.id)
        block.deallocate_ip(ip.address)

        seconds = config.Config.get('keep_deallocated_ips_for_seconds')
        self._push_back_deallocated_date(ip, seconds)

        script = tests.melange_bin_path('melange-delete-deallocated-ips')
        config_file = tests.test_config_file()
        functional.execute("{0} --config-file={1}".format(script, config_file))

        self.assertIsNone(models.IpAddress.get(ip.id))
Пример #5
0
    def test_deallocated_ips_get_freed(self):
        block = factory_models.PublicIpBlockFactory()
        ip = factory_models.IpAddressFactory(ip_block_id=block.id)
        block.deallocate_ip(ip.address)

        seconds = config.Config.get('keep_deallocated_ips_for_seconds')
        self._push_back_deallocated_date(ip, seconds)

        script = tests.melange_bin_path('melange-delete-deallocated-ips')
        config_file = tests.test_config_file()
        functional.execute("{0} --config-file={1}".format(script, config_file))

        # NOTE(jkoelker) Dirty, but works. Reset the session_maker so a
        #                new session is started in the current thread
        session._MAKER = None

        ip = models.IpAddress.get(ip.id)
        self.assertFalse(ip.allocated)
        self.assertIsNone(ip.interface)
        self.assertIsNone(ip.used_by_tenant_id)
Пример #6
0
def run_melange_manage(command):
    melange_manage = tests.melange_bin_path('melange-manage')
    config_file = tests.test_config_file()
    return functional.execute("%(melange_manage)s %(command)s "
                              "--config-file=%(config_file)s" % locals())
Пример #7
0
def run_melange_manage(command):
    cmd = dict(melange_manage=tests.melange_bin_path('melange-manage'),
               config_file=tests.test_config_file(),
               command=command)
    return functional.execute("%(melange_manage)s %(command)s "
                              "--config-file=%(config_file)s" % cmd)
Пример #8
0
def run_melange_manage(command):
    melange_manage = tests.melange_bin_path('melange-manage')
    config_file = tests.test_config_file()
    return functional.execute("%(melange_manage)s %(command)s "
                              "--config-file=%(config_file)s" % locals())