This repository has been archived by the owner on Aug 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Add supprt for iops #241
Merged
Merged
Add supprt for iops #241
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
image: rancher/dind:v1.9.0-rancher1 | ||
image: rancher/dind:v1.10.3-rancher1 | ||
script: | ||
- ./scripts/ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM rancher/dind:v1.9.0-rancher1 | ||
FROM rancher/dind:v1.10.3-rancher1 | ||
COPY ./scripts/bootstrap /scripts/bootstrap | ||
RUN /scripts/bootstrap | ||
WORKDIR /source |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import logging | ||
import platform | ||
import json | ||
|
||
log = logging.getLogger('iops') | ||
|
||
|
||
class IopsCollector(object): | ||
def __init__(self): | ||
self.data = {} | ||
|
||
def _get_iops_data(self, read_or_write): | ||
with open('/var/lib/rancher/state/' + read_or_write + '.json') as f: | ||
return json.load(f) | ||
|
||
def _parse_iops_file(self): | ||
data = {} | ||
|
||
try: | ||
read_json_data = self._get_iops_data('read') | ||
write_json_data = self._get_iops_data('write') | ||
except IOError: | ||
# File doesn't exist. Silently skip. | ||
return {} | ||
|
||
read_iops = read_json_data['jobs'][0]['read']['iops'] | ||
write_iops = write_json_data['jobs'][0]['write']['iops'] | ||
device = read_json_data['disk_util'][0]['name'] | ||
key = '/dev/' + device.encode('ascii', 'ignore') | ||
data[key] = {'read': read_iops, 'write': write_iops} | ||
return data | ||
|
||
def key_name(self): | ||
return "iopsInfo" | ||
|
||
def get_data(self): | ||
if platform.system() == 'Linux': | ||
if not self.data: | ||
self.data = self._parse_iops_file() | ||
return self.data | ||
else: | ||
return {} | ||
|
||
def get_default_disk(self): | ||
data = self.get_data() | ||
if not data: | ||
return None | ||
|
||
# Return the first and only item in the dict | ||
return data[data.keys()[0]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -825,6 +825,10 @@ def post(req, resp): | |
|
||
@if_docker | ||
def test_instance_activate_lxc_conf(agent, responses): | ||
if newer_than('1.22'): | ||
# lxc conf fields don't work in docker 1.10 and above | ||
return | ||
|
||
delete_container('/c861f990-4472-4fa1-960f-65171b544c28') | ||
expectedLxcConf = {"lxc.network.type": "veth"} | ||
|
||
|
@@ -906,6 +910,92 @@ def post(req, resp): | |
event_test(agent, schema, pre_func=pre, post_func=post) | ||
|
||
|
||
@if_docker | ||
def test_instance_activate_device_options(agent, responses): | ||
delete_container('/c861f990-4472-4fa1-960f-65171b544c28') | ||
# Note, can't test weight as it isn't supported in kernel by default | ||
device_options = {'/dev/sda': { | ||
'readIops': 1000, | ||
'writeIops': 2000, | ||
'readBps': 1024, | ||
'writeBps': 2048 | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you have a test case that options only has writeIops ? That ensure most user cases work, bc most of times, people won't put all options here. If you do have it, ignore my comment, it is jsut not clear to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Didn't have it @jimengliu. Added. |
||
} | ||
|
||
def pre(req): | ||
instance = req['data']['instanceHostMap']['instance'] | ||
instance['data']['fields']['blkioDeviceOptions'] = device_options | ||
|
||
def post(req, resp): | ||
instance_activate_assert_host_config(resp) | ||
instance_data = resp['data']['instanceHostMap']['instance']['+data'] | ||
host_config = instance_data['dockerInspect']['HostConfig'] | ||
assert host_config['BlkioDeviceReadIOps'] == [ | ||
{'Path': '/dev/sda', 'Rate': 1000}] | ||
assert host_config['BlkioDeviceWriteIOps'] == [ | ||
{'Path': '/dev/sda', 'Rate': 2000}] | ||
assert host_config['BlkioDeviceReadBps'] == [ | ||
{'Path': '/dev/sda', 'Rate': 1024}] | ||
assert host_config['BlkioDeviceWriteBps'] == [ | ||
{'Path': '/dev/sda', 'Rate': 2048}] | ||
container_field_test_boiler_plate(resp) | ||
|
||
schema = 'docker/instance_activate_fields' | ||
event_test(agent, schema, pre_func=pre, post_func=post) | ||
|
||
# Test DEFAULT_DISK functionality | ||
dc = DockerCompute() | ||
|
||
device = '/dev/mock' | ||
|
||
class MockHostInfo(object): | ||
def get_default_disk(self): | ||
return device | ||
|
||
dc.host_info = MockHostInfo() | ||
instance = JsonObject({'data': {}}) | ||
instance.data['fields'] = { | ||
'blkioDeviceOptions': { | ||
'DEFAULT_DISK': {'readIops': 10} | ||
} | ||
} | ||
config = {} | ||
dc._setup_device_options(config, instance) | ||
assert config['BlkioDeviceReadIOps'] == [{'Path': '/dev/mock', 'Rate': 10}] | ||
|
||
config = {} | ||
device = None | ||
dc._setup_device_options(config, instance) | ||
assert not config # config should be empty | ||
|
||
|
||
@if_docker | ||
def test_instance_activate_single_device_option(agent, responses): | ||
delete_container('/c861f990-4472-4fa1-960f-65171b544c28') | ||
device_options = {'/dev/sda': { | ||
'writeIops': 2000, | ||
} | ||
} | ||
|
||
def pre(req): | ||
instance = req['data']['instanceHostMap']['instance'] | ||
instance['data']['fields']['blkioDeviceOptions'] = device_options | ||
|
||
def post(req, resp): | ||
instance_activate_assert_host_config(resp) | ||
instance_data = resp['data']['instanceHostMap']['instance']['+data'] | ||
host_config = instance_data['dockerInspect']['HostConfig'] | ||
assert host_config['BlkioDeviceWriteIOps'] == [ | ||
{'Path': '/dev/sda', 'Rate': 2000}] | ||
assert host_config['BlkioDeviceReadIOps'] is None | ||
assert host_config['BlkioDeviceReadBps'] is None | ||
assert host_config['BlkioDeviceWriteBps'] is None | ||
container_field_test_boiler_plate(resp) | ||
|
||
schema = 'docker/instance_activate_fields' | ||
event_test(agent, schema, pre_func=pre, post_func=post) | ||
|
||
|
||
@if_docker | ||
def test_instance_activate_dns(agent, responses): | ||
delete_container('/c861f990-4472-4fa1-960f-65171b544c28') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to check array length value here? or is it safe to assume that it's always > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alena, that is the FIO output json file, it should always have the same format, the value could be 0, but items always there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jimengliu cool