'This is a basic test that check that a QoS policy with
a bandwidth limit rule is applied correctly by sending
a file from the instance to the test node.
Then calculating the bandwidth every ~1 sec by the number of bits
received / elapsed time.'

@decorators.idempotent_id('1f7ed39b-428f-410a-bd2b-db9f465680df')
def test_qos(self):

    NC_PORT = 1234
    self.setup_network_and_server()
    self.check_connectivity(self.fip['floating_ip_address'], CONF.validation.image_ssh_user, self.keypair['private_key'])
    rulesets = [{'protocol': 'tcp', 'direction': 'ingress', 'port_range_min': NC_PORT, 'port_range_max': NC_PORT, 'remote_ip_prefix': '0.0.0.0/0'}]
    self.create_secgroup_rules(rulesets, self.security_groups[(-1)]['id'])
    ssh_client = ssh.Client(self.fip['floating_ip_address'], CONF.validation.image_ssh_user, pkey=self.keypair['private_key'])
    policy = self.os_admin.network_client.create_qos_policy(name='test-policy', description='test-qos-policy', shared=True)
    policy_id = policy['policy']['id']
    self.os_admin.network_client.create_bandwidth_limit_rule(policy_id, max_kbps=constants.LIMIT_KILO_BITS_PER_SECOND, max_burst_kbps=constants.LIMIT_KILO_BITS_PER_SECOND)
    port = self.client.list_ports(network_id=self.network['id'], device_id=self.server['server']['id'])['ports'][0]
    self.os_admin.network_client.update_port(port['id'], qos_policy_id=policy_id)
    self._create_file_for_bw_tests(ssh_client)
    utils.wait_until_true((lambda : self._check_bw(ssh_client, self.fip['floating_ip_address'], port=NC_PORT)), timeout=120, sleep=1)
