def setUp(self):
     self.ssh_utils = SSH_Utils({})
     self.compute_nodes_key = "key"
     self.iops_reference = 50
     self.bs_reference = 10000000
     self.remote_kvm = Remote_KVM(self.ssh_utils, self.compute_nodes_key,
                                  self.iops_reference, self.bs_reference)
     self.cap = 56
     self.host_ip = "vm-ip"
     self.vm_id = "vm-id"
     self.io_quota = 1000
Beispiel #2
0
    def setUp(self):
        self.vm_id1 = "vm_id1"
        self.vm_id2 = "vm_id2"

        self.host_ip1 = "host_ip1"
        self.host_ip2 = "host_ip2"

        self.cap1 = 50
        self.cap2 = 78
        self.io_cap = 75

        self.bigsea_username = "******"
        self.bigsea_password = "******"
        self.authorization_url = "authorization_url"
        self.authorization_data = dict(
            authorization_url=self.authorization_url,
            bigsea_username=self.bigsea_username,
            bigsea_password=self.bigsea_password)

        compute_nodes = []
        compute_nodes_key = "key"
        self.instance_locator = Instance_Locator(SSH_Utils({}), compute_nodes,
                                                 compute_nodes_key)
        self.remote_kvm = Remote_KVM(SSH_Utils({}), compute_nodes_key)
        self.actuator = KVM_Actuator(self.instance_locator, self.remote_kvm,
                                     self.authorization_data, self.io_cap)
    def setUp(self):
        self.application_id_0 = "app-00"
        self.application_id_1 = "app-01"
        self.application_id_2 = "app-02"

        self.timestamp_1 = datetime.datetime.strptime("2000-01-01T00:00:00.0Z",
                                                      '%Y-%m-%dT%H:%M:%S.%fZ')
        self.timestamp_2 = datetime.datetime.strptime("2000-01-01T00:05:00.0Z",
                                                      '%Y-%m-%dT%H:%M:%S.%fZ')
        self.timestamp_3 = datetime.datetime.strptime("2000-01-01T00:10:00.0Z",
                                                      '%Y-%m-%dT%H:%M:%S.%fZ')
        self.timestamp_4 = datetime.datetime.strptime("2000-01-01T00:15:00.0Z",
                                                      '%Y-%m-%dT%H:%M:%S.%fZ')

        self.instance_name_1 = "instance1"
        self.instance_name_2 = "instance2"
        self.instances = [self.instance_name_1, self.instance_name_2]

        self.trigger_down = 30.0
        self.trigger_up = 10.0
        self.min_cap = 10.0
        self.max_cap = 100.0
        self.actuation_size = 10.0
        self.allocated_resources = 50
        self.metric_round = 2
        self.default_io_cap = 78

        self.bigsea_username = "******"
        self.bigsea_password = "******"
        self.authorization_url = "authorization_url"
        self.authorization_data = dict(authorization_url=self.authorization_url,
                                       bigsea_username=self.bigsea_username,
                                       bigsea_password=self.bigsea_password)

        compute_nodes = []
        compute_nodes_key = "key"
        self.instances = [self.instance_name_1, self.instance_name_2]
        self.metric_source = Metric_Source_Builder().get_metric_source("nop", {})
        self.instance_locator = Instance_Locator(
            SSH_Utils({}), compute_nodes, compute_nodes_key)
        self.remote_kvm = Remote_KVM(SSH_Utils({}), compute_nodes_key)
        self.actuator = KVM_Actuator(self.instance_locator, self.remote_kvm, self.authorization_data,
                                     self.default_io_cap)

        self.proportional_factor = 1
        self.factor_up = 1
        self.factor_down = 0.5
        self.heuristic_options_error_proportional = {"heuristic_name": "error_proportional",
                                                     "proportional_factor": self.proportional_factor}
        self.heuristic_options_error_proportional_up_down = \
            {"heuristic_name": "error_proportional_up_down",
             "factor_up": self.factor_up,
             "factor_down": self.factor_down}

        self.progress_error = {self.application_id_0: -20.0,
                               self.application_id_1: 0.00, self.application_id_2: 30.0}

        self.timestamps = [self.timestamp_1, self.timestamp_2,
                           self.timestamp_3, self.timestamp_4]
    def setUp(self):
        self.application_id_0 = "app-00"
        self.application_id_1 = "app-01"
        self.application_id_2 = "app-02"
        self.application_id_3 = "app-03"
        self.application_id_4 = "app-04"

        self.timestamp_1 = datetime.datetime.strptime("2000-01-01T00:00:00.0Z",
                                                      '%Y-%m-%dT%H:%M:%S.%fZ')
        self.timestamp_2 = datetime.datetime.strptime("2000-01-01T00:05:00.0Z",
                                                      '%Y-%m-%dT%H:%M:%S.%fZ')
        self.timestamp_3 = datetime.datetime.strptime("2000-01-01T00:10:00.0Z",
                                                      '%Y-%m-%dT%H:%M:%S.%fZ')
        self.timestamp_4 = datetime.datetime.strptime("2000-01-01T00:15:00.0Z",
                                                      '%Y-%m-%dT%H:%M:%S.%fZ')

        self.instance_name_1 = "instance1"
        self.instance_name_2 = "instance2"
        self.instances = [self.instance_name_1, self.instance_name_2]

        self.trigger_down = 30.0
        self.trigger_up = 10.0
        self.min_cap = 10.0
        self.max_cap = 100.0
        self.actuation_size = 10.0
        self.allocated_resources = 50
        self.metric_round = 2
        self.default_io_cap = 45

        self.bigsea_username = "******"
        self.bigsea_password = "******"
        self.authorization_url = "authorization_url"
        self.authorization_data = dict(
            authorization_url=self.authorization_url,
            bigsea_username=self.bigsea_username,
            bigsea_password=self.bigsea_password)

        compute_nodes = []
        compute_nodes_key = "key"
        self.instances = [self.instance_name_1, self.instance_name_2]
        self.metric_source = Metric_Source_Builder().get_metric_source(
            "nop", {})
        self.instance_locator = Instance_Locator(SSH_Utils({}), compute_nodes,
                                                 compute_nodes_key)
        self.remote_kvm = Remote_KVM(SSH_Utils({}), compute_nodes_key)
        self.actuator = KVM_Actuator(self.instance_locator, self.remote_kvm,
                                     self.authorization_data,
                                     self.default_io_cap)

        self.timestamps = [
            self.timestamp_1, self.timestamp_2, self.timestamp_3,
            self.timestamp_4
        ]
class Test_Remote_KVM(unittest.TestCase):
    def setUp(self):
        self.ssh_utils = SSH_Utils({})
        self.compute_nodes_key = "key"
        self.iops_reference = 50
        self.bs_reference = 10000000
        self.remote_kvm = Remote_KVM(self.ssh_utils, self.compute_nodes_key,
                                     self.iops_reference, self.bs_reference)
        self.cap = 56
        self.host_ip = "vm-ip"
        self.vm_id = "vm-id"
        self.io_quota = 1000

    #
    # change_cpu_quota
    #

    def test_change_cpu_quota(self):
        self.ssh_utils.run_command = MagicMock(return_value=None)

        self.remote_kvm.change_vcpu_quota(self.host_ip, self.vm_id, self.cap)

        command = "virsh schedinfo %s" \
            " --set vcpu_quota=$(( %s * `virsh schedinfo %s | awk 'FNR == 3 {print $3}'`/100 ))" \
            " > /dev/null" % (self.vm_id, self.cap, self.vm_id)

        self.ssh_utils.run_command.assert_called_once_with(
            command, "root", self.host_ip, self.compute_nodes_key)

    def test_change_cpu_quota_negative_cap_value(self):
        self.assertRaises(Exception, self.remote_kvm.change_vcpu_quota,
                          self.host_ip, self.vm_id, -10,
                          self.compute_nodes_key)

    def test_change_cpu_quota_too_high_cap_value(self):
        self.assertRaises(Exception, self.remote_kvm.change_vcpu_quota,
                          self.host_ip, self.vm_id, 100 + 20,
                          self.compute_nodes_key)

    #
    # change_io_quota
    #

    def test_change_io_quota(self):
        command_iops_quota = (self.cap * self.iops_reference) / 100
        command_bs_quota = (self.cap * self.bs_reference) / 100
        command_set_io_quota = "virsh blkdeviotune %s" \
            " \"`virsh domblklist %s | awk 'FNR == 3 {print $1}'`\"" \
            " --current --total_iops_sec %s --total_bytes_sec %s" % (self.vm_id, self.vm_id,
                                                                     command_iops_quota, command_bs_quota)

        self.ssh_utils.run_command = MagicMock(return_value=None)

        self.remote_kvm.change_io_quota(self.host_ip, self.vm_id, self.cap)

        self.ssh_utils.run_command.assert_called_once_with(
            command_set_io_quota, "root", self.host_ip, self.compute_nodes_key)

    def test_change_io_quota_negative_cap_value(self):
        self.assertRaises(Exception, self.remote_kvm.change_io_quota,
                          self.host_ip, self.vm_id, -10,
                          self.compute_nodes_key)

    def test_change_io_quota_too_high_cap_value(self):
        self.assertRaises(Exception, self.remote_kvm.change_io_quota,
                          self.host_ip, self.vm_id, 100 + 20,
                          self.compute_nodes_key)

    def test_get_allocated_resources_success(self):
        self.ssh_utils.run_and_get_result = MagicMock(return_value="56")

        result_cap = self.remote_kvm.get_allocated_resources(
            self.host_ip, self.vm_id)

        self.assertEquals(result_cap, 56)

        command = "virsh schedinfo %s" \
            " | awk '{if(NR==3){period=$3} if(NR==4){print 100*$3/period}}'" % (self.vm_id)
        self.ssh_utils.run_and_get_result.assert_called_once_with(
            command, "root", self.host_ip, self.compute_nodes_key)

    #
    # get_cpu_quota
    #

    def test_get_allocated_resources_virsh_returns_negative_1(self):
        self.ssh_utils.run_and_get_result = MagicMock(return_value="-1")

        result_cap = self.remote_kvm.get_allocated_resources(
            self.host_ip, self.vm_id)

        self.assertEquals(result_cap, 100)

        command = "virsh schedinfo %s" \
            " | awk '{if(NR==3){period=$3} if(NR==4){print 100*$3/period}}'" % (self.vm_id)
        self.ssh_utils.run_and_get_result.assert_called_once_with(
            command, "root", self.host_ip, self.compute_nodes_key)

    def test_get_allocated_resources_ssh_returns_empty_string(self):
        self.ssh_utils.run_and_get_result = MagicMock(return_value="")

        self.assertRaises(Exception, self.remote_kvm.get_allocated_resources,
                          self.host_ip, self.vm_id, self.compute_nodes_key)

    #
    # get_io_quota
    #

    def get_io_quota_ssh_values(self, command, user, host, key):
        if "blkdeviotune" in command:
            return str(self.io_quota)
        elif "domblklist" in command:
            return self.block_device

    def test_get_io_quota(self):
        command_get_io_quota = "virsh blkdeviotune %s" \
            " \"`virsh domblklist %s | awk 'FNR == 3 {print $1}'`\"" \
            " | grep total_iops_sec: | awk '{print $2}'" % (
                self.vm_id, self.vm_id)

        self.ssh_utils.run_and_get_result = MagicMock()
        self.ssh_utils.run_and_get_result.side_effect = self.get_io_quota_ssh_values

        quota = self.remote_kvm.get_io_quota(self.host_ip, self.vm_id)

        self.assertEqual(quota,
                         100 * float(self.io_quota) / self.iops_reference)
        self.ssh_utils.run_and_get_result.assert_any_call(
            command_get_io_quota, "root", self.host_ip, self.compute_nodes_key)

    def test_get_io_quota_ssh_returns_empty_string(self):
        self.ssh_utils.run_and_get_result = MagicMock(return_value="")

        self.assertRaises(Exception, self.remote_kvm.get_io_quota,
                          self.host_ip, self.vm_id, self.compute_nodes_key)
Beispiel #6
0
    def setUp(self):
        self.application_id_0 = "app-00"
        self.application_id_1 = "app-01"
        self.application_id_2 = "app-02"
        self.application_id_3 = "app-03"
        self.application_id_4 = "app-04"
        self.application_id_5 = "app-05"
        self.application_id_6 = "app-06"
        self.application_id_7 = "app-07"

        self.timestamp_1 = datetime.datetime.strptime("2000-01-01T00:00:00.0Z",
                                                      "%Y-%m-%dT%H:%M:%S.%fZ")
        self.timestamp_2 = datetime.datetime.strptime("2000-01-01T00:05:00.0Z",
                                                      "%Y-%m-%dT%H:%M:%S.%fZ")
        self.timestamp_3 = datetime.datetime.strptime("2000-01-01T00:10:00.0Z",
                                                      "%Y-%m-%dT%H:%M:%S.%fZ")
        self.timestamp_4 = datetime.datetime.strptime("2000-01-01T00:15:00.0Z",
                                                      "%Y-%m-%dT%H:%M:%S.%fZ")

        self.timestamps = [
            self.timestamp_1, self.timestamp_2, self.timestamp_3,
            self.timestamp_4
        ]

        self.instance_name_1 = "instance1"
        self.instance_name_2 = "instance2"
        self.instances = [self.instance_name_1, self.instance_name_2]

        self.trigger_down = 10.0
        self.trigger_up = 10.0
        self.min_cap = 10.0
        self.max_cap = 100.0
        self.actuation_size = 10.0
        self.allocated_resources_scale_down = 100
        self.allocated_resources_scale_up = 10
        self.metric_round = 2
        self.default_io_cap = 34

        self.bigsea_username = "******"
        self.bigsea_password = "******"
        self.authorization_url = "authorization_url"
        self.authorization_data = dict(
            authorization_url=self.authorization_url,
            bigsea_username=self.bigsea_username,
            bigsea_password=self.bigsea_password)

        compute_nodes = []
        compute_nodes_key = "key"
        self.instances = [self.instance_name_1, self.instance_name_2]
        self.metric_source = Metric_Source_Builder().get_metric_source(
            "nop", {})
        self.instance_locator = Instance_Locator(SSH_Utils({}), compute_nodes,
                                                 compute_nodes_key)
        self.remote_kvm = Remote_KVM(SSH_Utils({}), compute_nodes_key)
        self.actuator = KVM_Actuator(self.instance_locator, self.remote_kvm,
                                     self.authorization_data,
                                     self.default_io_cap)

        self.proportional_factor = 1.5
        self.derivative_factor = 0.5

        self.heuristic_options = {
            "heuristic_name": "error_proportional_derivative",
            "proportional_factor": self.proportional_factor,
            "derivative_factor": self.derivative_factor
        }

        self.progress_error = {
            # CASE 1
            self.application_id_0: {
                self.timestamp_1: -30.0,
                self.timestamp_2: -20.0,
                self.timestamp_3: -15.0
            },

            # CASE 2
            self.application_id_1: {
                self.timestamp_1: -30.0,
                self.timestamp_2: -40.0,
                self.timestamp_3: -60.0
            },

            # CASE 3
            self.application_id_2: {
                self.timestamp_1: 30.0,
                self.timestamp_2: 20.0,
                self.timestamp_3: 15.0
            },

            # CASE 4
            self.application_id_3: {
                self.timestamp_1: 30.0,
                self.timestamp_2: 40.0,
                self.timestamp_3: 55.0
            },

            # CASE 5
            self.application_id_4: {
                self.timestamp_1: 100.0,
                self.timestamp_2: 100.0,
                self.timestamp_3: 100.0
            },

            # CASE 6
            self.application_id_5: {
                self.timestamp_1: -100.0,
                self.timestamp_2: -100.0,
                self.timestamp_3: -100.0
            },

            # CASE 7
            self.application_id_6: {
                self.timestamp_1: -30.0,
                self.timestamp_2: 10.0,
                self.timestamp_3: 30.0
            },

            # CASE 8
            self.application_id_7: {
                self.timestamp_1: -5.0,
                self.timestamp_2: -1.0,
                self.timestamp_3: 2.0
            }
        }