예제 #1
0
    def run(self, **kwargs):
        cfg = self.cloud.cloud_config.cloud
        runner = remote_runner.RemoteRunner(cfg.ssh_host, cfg.ssh_user)

        with files.LocalTempDir('check_band_XXXX') as local_dir:
            with files.RemoteTempDir(runner, 'check_band_XXXX') as remote_dir:
                filename = str(uuid.uuid4())
                local_filepath = os.path.join(local_dir.dirname, filename)
                remote_filepath = os.path.join(remote_dir.dirname, filename)
                claimed_bandw = self.cloud.cloud_config.initial_check.\
                    claimed_bandwidth
                filesize = self.cloud.cloud_config.initial_check.test_file_size
                factor = self.cloud.cloud_config.initial_check.factor
                req_bandwidth = claimed_bandw * factor

                scp_download = "scp {ssh_opts} {user}@{host}:{filepath} " \
                               "{dirname}"
                scp_upload = "scp {ssh_opts} {filepath} {user}@{host}:" \
                             "{dirname}"
                dd_command = "dd if=/dev/zero of={filepath} bs=1 count=0 " \
                             "seek={filesize}"
                runner.run(dd_command,
                           filepath=remote_filepath,
                           filesize=filesize)

                LOG.info("Checking download speed... Wait please.")
                period_download = utils.timer(
                    local.run,
                    scp_download.format(
                        ssh_opts=ssh_util.default_ssh_options(),
                        user=cfg.ssh_user,
                        host=cfg.ssh_host,
                        filepath=remote_filepath,
                        dirname=local_dir.dirname))

                LOG.info("Checking upload speed... Wait please.")
                period_upload = utils.timer(
                    local.run,
                    scp_upload.format(ssh_opts=ssh_util.default_ssh_options(),
                                      filepath=local_filepath,
                                      user=cfg.ssh_user,
                                      host=cfg.ssh_host,
                                      dirname=remote_dir.dirname))

        # To have Megabits per second
        upload_speed = filesize / period_upload * 8
        download_speed = filesize / period_download * 8

        if upload_speed < req_bandwidth or download_speed < req_bandwidth:
            raise RuntimeError(
                'Bandwidth is not OK. '
                'Claimed bandwidth: %s Mb/s. '
                'Required speed: %s Mb/s. '
                'Actual upload speed: %.2f Mb/s. '
                'Actual download speed: %.2f Mb/s. '
                'Aborting migration...' %
                (claimed_bandw, req_bandwidth, upload_speed, download_speed))

        LOG.info(
            "Bandwith is OK. "
            "Required speed: %.2f Mb/s. "
            "Upload speed: %.2f Mb/s. "
            "Download speed: %.2f Mb/s", req_bandwidth, upload_speed,
            download_speed)
예제 #2
0
    def run(self, **kwargs):
        cfg = self.cloud.cloud_config.cloud
        runner = remote_runner.RemoteRunner(cfg.ssh_host, cfg.ssh_user)

        with files.LocalTempDir('check_band_XXXX') as local_dir:
            with files.RemoteTempDir(runner, 'check_band_XXXX') as remote_dir:
                filename = str(uuid.uuid4())
                local_filepath = os.path.join(local_dir.dirname, filename)
                remote_filepath = os.path.join(remote_dir.dirname, filename)
                claimed_bandw = self.cloud.cloud_config.initial_check.\
                    claimed_bandwidth
                filesize = self.cloud.cloud_config.initial_check.test_file_size
                factor = self.cloud.cloud_config.initial_check.factor
                req_bandwidth = claimed_bandw * factor

                scp_download = "scp {ssh_opts} {user}@{host}:{filepath} " \
                               "{dirname}"
                scp_upload = "scp {ssh_opts} {filepath} {user}@{host}:" \
                             "{dirname}"
                dd_command = "dd if=/dev/zero of={filepath} bs=1 count=0 " \
                             "seek={filesize}"
                runner.run(dd_command,
                           filepath=remote_filepath,
                           filesize=filesize)

                LOG.info("Checking download speed... Wait please.")
                period_download = utils.timer(
                    local.run,
                    scp_download.format(
                        ssh_opts=ssh_util.default_ssh_options(),
                        user=cfg.ssh_user,
                        host=cfg.ssh_host,
                        filepath=remote_filepath,
                        dirname=local_dir.dirname
                    )
                )

                LOG.info("Checking upload speed... Wait please.")
                period_upload = utils.timer(
                    local.run,
                    scp_upload.format(
                        ssh_opts=ssh_util.default_ssh_options(),
                        filepath=local_filepath,
                        user=cfg.ssh_user,
                        host=cfg.ssh_host,
                        dirname=remote_dir.dirname
                    )
                )

        # To have Megabits per second
        upload_speed = filesize / period_upload * 8
        download_speed = filesize / period_download * 8

        if upload_speed < req_bandwidth or download_speed < req_bandwidth:
            raise RuntimeError('Bandwidth is not OK. '
                               'Claimed bandwidth: %s Mb/s. '
                               'Required speed: %s Mb/s. '
                               'Actual upload speed: %.2f Mb/s. '
                               'Actual download speed: %.2f Mb/s. '
                               'Aborting migration...' %
                               (claimed_bandw,
                                req_bandwidth,
                                upload_speed,
                                download_speed))

        LOG.info("Bandwith is OK. "
                 "Required speed: %.2f Mb/s. "
                 "Upload speed: %.2f Mb/s. "
                 "Download speed: %.2f Mb/s",
                 req_bandwidth,
                 upload_speed,
                 download_speed)
예제 #3
0
    def run(self, **kwargs):
        cfg = self.cloud.cloud_config.cloud
        runner = remote_runner.RemoteRunner(cfg.ssh_host, cfg.ssh_user)

        temp_dir_name = os.popen('mktemp -dt check_band_XXXX').read().rstrip()
        temp_file_name = str(uuid.uuid4())

        claimed_bandw = self.cloud.cloud_config.initial_check.claimed_bandwidth
        test_file_size = self.cloud.cloud_config.initial_check.test_file_size

        ssh_user = self.cloud.cloud_config.cloud.ssh_user

        factor = self.cloud.cloud_config.initial_check.factor
        req_bandwidth = claimed_bandw * factor

        local_file_path = os.path.join(temp_dir_name, temp_file_name)
        remote_file_path = os.path.join(temp_dir_name,
                                        temp_file_name)

        scp_upload = cmd_cfg.scp_cmd(ssh_util.get_cipher_option(),
                                     '',
                                     ssh_user,
                                     cfg.ssh_host,
                                     remote_file_path,
                                     temp_dir_name)

        scp_download = cmd_cfg.scp_cmd(ssh_util.get_cipher_option(),
                                       local_file_path,
                                       ssh_user,
                                       cfg.ssh_host,
                                       temp_dir_name,
                                       '')

        with files.RemoteDir(runner, temp_dir_name):
            try:
                with utils.forward_agent(env.key_filename):
                    dd_command = cmd_cfg.dd_full('/dev/zero',
                                                 remote_file_path,
                                                 1,
                                                 0,
                                                 test_file_size)
                    self.cloud.ssh_util.execute(dd_command)

                    LOG.info("Checking upload speed... Wait please.")
                    period_upload = utils.timer(subprocess.call,
                                                str(scp_upload),
                                                shell=True)

                    LOG.info("Checking download speed... Wait please.")
                    period_download = utils.timer(subprocess.call,
                                                  str(scp_download),
                                                  shell=True)
            finally:
                if len(temp_dir_name) > 1:
                    os.system("rm -rf {}".format(temp_dir_name))
                else:
                    raise RuntimeError('Wrong dirname %s, stopping' %
                                       temp_dir_name)

        # To have Megabits per second
        upload_speed = test_file_size / period_upload * 8
        download_speed = test_file_size / period_download * 8

        if upload_speed < req_bandwidth or download_speed < req_bandwidth:
            raise RuntimeError('Bandwidth is not OK. '
                               'Claimed bandwidth: %s Mb/s. '
                               'Required speed: %s Mb/s. '
                               'Actual upload speed: %.2f Mb/s. '
                               'Actual download speed: %.2f Mb/s. '
                               'Aborting migration...' %
                               (claimed_bandw,
                                req_bandwidth,
                                upload_speed,
                                download_speed))

        LOG.info("Bandwith is OK. "
                 "Required speed: %.2f Mb/s. "
                 "Upload speed: %.2f Mb/s. "
                 "Download speed: %.2f Mb/s",
                 req_bandwidth,
                 upload_speed,
                 download_speed)