From 106832eaae61743983e572b8af363ce1ea04ee6b Mon Sep 17 00:00:00 2001 From: Will Miller Date: Fri, 7 Sep 2018 09:05:58 +0000 Subject: [PATCH 1/8] Add Travis CI config file --- .travis.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..570bce4 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,32 @@ +--- +language: python +python: "2.7" + +# Run jobs in VMs - sudo is required by ansible tests. +sudo: required + +# Install ansible +addons: + apt: + packages: + - gcc + - python-apt + - python-virtualenv + - realpath + +# Create a build matrix for the different test jobs. +env: + matrix: + # Run python style checks. + - TOX_ENV=pep8 + # Run Ansible linting. + - TOX_ENV=alint + +install: + # Install tox in a virtualenv to ensure we have an up to date version. + - pip install -U pip + - pip install tox + +script: + # Run the tox environment. + - tox -e ${TOX_ENV} From 24900f4e52bba3fc0e8444286ae6e9a9fad62887 Mon Sep 17 00:00:00 2001 From: Will Miller Date: Fri, 7 Sep 2018 09:19:10 +0000 Subject: [PATCH 2/8] Use basepython of 2.7 --- tox.ini | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tox.ini b/tox.ini index b56cbe0..f0c4e94 100644 --- a/tox.ini +++ b/tox.ini @@ -23,12 +23,12 @@ deps = -r{toxinidir}/test-requirements.txt [testenv:pep8] -basepython = python3 +basepython = python2.7 commands = flake8 {posargs} [testenv:alint] -basepython = python3 +basepython = python2.7 # ansible-lint doesn't support custom modules, so add ours to the Ansible path. setenv = ANSIBLE_LIBRARY = {toxinidir}/ansible/action_plugins/ # Exclude roles downloaded from Galaxy (in the form 'author.role') from From 8b44c718b4c5baeee1e970e0ccf6a811ef358580 Mon Sep 17 00:00:00 2001 From: Will Miller Date: Fri, 7 Sep 2018 13:18:42 +0100 Subject: [PATCH 3/8] Use round-robin scheduling instead of all-on-one --- ansible/action_plugins/tenks_schedule.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/ansible/action_plugins/tenks_schedule.py b/ansible/action_plugins/tenks_schedule.py index 275f8ba..62973dd 100644 --- a/ansible/action_plugins/tenks_schedule.py +++ b/ansible/action_plugins/tenks_schedule.py @@ -43,11 +43,14 @@ class ActionModule(ActionBase): hostname of the hypervisor to which they are scheduled. """ result = super(ActionModule, self).run(tmp, task_vars) + # Initialise our return dict. + result['result'] = {} del tmp # tmp no longer has any effect self._validate_vars(task_vars) nodes = [] idx = 0 + hypervisor_names = task_vars['hypervisor_vars'].keys() for typ, cnt in six.iteritems(task_vars['specs']): for _ in six.moves.range(cnt): node = deepcopy(task_vars['node_types'][typ]) @@ -59,12 +62,15 @@ class ActionModule(ActionBase): vol['name'] = "%s%d" % (task_vars['vol_name_prefix'], vol_idx) nodes.append(node) + # Perform round-robin scheduling with node index modulo number + # of hypervisors. + hyp_name = hypervisor_names[idx % len(hypervisor_names)] + try: + result['result'][hyp_name].append(node) + except KeyError: + # This hypervisor doesn't yet have any scheduled nodes. + result['result'][hyp_name] = [node] idx += 1 - - # TODO(w-miller): currently we just arbitrarily schedule all nodes to - # the first hypervisor. Improve this algorithm to make it more - # sophisticated. - result['result'] = {task_vars['hypervisor_vars'].keys()[0]: nodes} return result def _validate_vars(self, task_vars): From af98a202499cd159783dc97258b5175e0b1cd4ea Mon Sep 17 00:00:00 2001 From: Will Miller Date: Fri, 7 Sep 2018 13:21:29 +0100 Subject: [PATCH 4/8] Fix upper constraints typo --- ansible/deploy_hosts.yml | 3 ++- ansible/roles/virtualbmc-daemon/tasks/main.yml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ansible/deploy_hosts.yml b/ansible/deploy_hosts.yml index a8cbbdf..a5e59ed 100644 --- a/ansible/deploy_hosts.yml +++ b/ansible/deploy_hosts.yml @@ -24,4 +24,5 @@ name: virtualbmc-daemon vars: vbmcd_virtualenv_path: "{{ virtualenv_path }}" - vbmcd_python_upper_contraints_url: "{{ python_upper_constraints_url }}" + vbmcd_python_upper_constraints_url: >- + {{ python_upper_constraints_url }} diff --git a/ansible/roles/virtualbmc-daemon/tasks/main.yml b/ansible/roles/virtualbmc-daemon/tasks/main.yml index c850a50..937d90f 100644 --- a/ansible/roles/virtualbmc-daemon/tasks/main.yml +++ b/ansible/roles/virtualbmc-daemon/tasks/main.yml @@ -10,7 +10,7 @@ pip: requirements: "{{ '/'.join([role_path, 'files', 'requirements.txt']) }}" extra_args: >- - -c {{ vbmcd_python_upper_contraints_url }} + -c {{ vbmcd_python_upper_constraints_url }} virtualenv: "{{ vbmcd_virtualenv_path }}" - name: Ensure Virtual BMC systemd service is configured From 768af20e849b5f738a1051e4184577d1f64a0ca2 Mon Sep 17 00:00:00 2001 From: Will Miller Date: Fri, 7 Sep 2018 13:22:06 +0100 Subject: [PATCH 5/8] Move pip settings to group_vars/all We need to use pip on localhost as well as on hypervisors, for Ironic enrolment. --- ansible/group_vars/all | 9 +++++++++ ansible/group_vars/hypervisors | 9 --------- 2 files changed, 9 insertions(+), 9 deletions(-) create mode 100644 ansible/group_vars/all diff --git a/ansible/group_vars/all b/ansible/group_vars/all new file mode 100644 index 0000000..6eee2da --- /dev/null +++ b/ansible/group_vars/all @@ -0,0 +1,9 @@ +--- +# Path to virtualenv used to install Python requirements. If a virtualenv does +# not exist at this location, one will be created. +virtualenv_path: "{{ '/'.join([ansible_env['HOME'], 'tenks-venv']) }}" + +# The URL of the upper constraints file to pass to pip when installing Python +# packages. +python_upper_constraints_url: >- + https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt diff --git a/ansible/group_vars/hypervisors b/ansible/group_vars/hypervisors index 4b7eb96..dc6dcad 100644 --- a/ansible/group_vars/hypervisors +++ b/ansible/group_vars/hypervisors @@ -6,15 +6,6 @@ physnet_mappings: {} system_requirements: - python-virtualenv -# Path to virtualenv used to install Python requirements. If a virtualenv does -# not exist at this location, one will be created. -virtualenv_path: "{{ '/'.join([ansible_env['HOME'], 'tenks-venv']) }}" - -# The URL of the upper constraints file to pass to pip when installing Python -# packages. -python_upper_constraints_url: >- - https://git.openstack.org/cgit/openstack/requirements/plain/upper-constraints.txt - # Naming scheme for bridges created by tenks for physical networks is # {{ bridge_prefix + i }}, where `i` is the index of the physical network in # physnet_mappings (sorted alphabetically by key). From 3066438a7fc10fffd2e6d3a666cb805daf607092 Mon Sep 17 00:00:00 2001 From: Will Miller Date: Fri, 7 Sep 2018 13:23:00 +0100 Subject: [PATCH 6/8] Use full path for ip command --- ansible/physical_network.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ansible/physical_network.yml b/ansible/physical_network.yml index f806a55..9957bbb 100644 --- a/ansible/physical_network.yml +++ b/ansible/physical_network.yml @@ -13,7 +13,8 @@ source_type: direct - name: Get source interface details - command: ip -details link show {{ source_interface }} + # NOTE(w-miller): The `ip` command may not be in $PATH, so use the full path. + command: /usr/sbin/ip -details link show {{ source_interface }} register: if_details changed_when: false From 9b1ad58146832e2c3576ee0b4b7f628b2ed098e8 Mon Sep 17 00:00:00 2001 From: Will Miller Date: Fri, 7 Sep 2018 13:23:22 +0100 Subject: [PATCH 7/8] Use become for all Open vSwitch tasks --- ansible/physical_network.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ansible/physical_network.yml b/ansible/physical_network.yml index 9957bbb..4f30b95 100644 --- a/ansible/physical_network.yml +++ b/ansible/physical_network.yml @@ -70,6 +70,7 @@ type=patch options:peer={{ veth_prefix + tenks_bridge + veth_bridge_source_suffix }} + become: true - name: Create patch port on source bridge openvswitch_port: @@ -80,9 +81,11 @@ type=patch options:peer={{ veth_prefix + tenks_bridge + veth_bridge_ovs_suffix }} + become: true - name: Plug source interface into Tenks bridge when: source_type == 'direct' openvswitch_port: bridge: "{{ tenks_bridge }}" port: "{{ source_interface }}" + become: true From 7f21b4c8c1c377c23dfa56be30cd4bdc9a5773c3 Mon Sep 17 00:00:00 2001 From: Will Miller Date: Fri, 7 Sep 2018 13:24:01 +0100 Subject: [PATCH 8/8] Copy requirements file to remote host The pip module requires that the requirements.txt file exists on the remote host, so copy it to a temporary location. --- ansible/roles/ironic-enrolment/tasks/main.yml | 12 +++++++++++- ansible/roles/virtualbmc-daemon/tasks/main.yml | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ansible/roles/ironic-enrolment/tasks/main.yml b/ansible/roles/ironic-enrolment/tasks/main.yml index 8196d24..875f4b7 100644 --- a/ansible/roles/ironic-enrolment/tasks/main.yml +++ b/ansible/roles/ironic-enrolment/tasks/main.yml @@ -1,7 +1,17 @@ --- +# This is useful to get a uniquely generated temporary path. +- name: Create temporary file for pip requirements + tempfile: + register: req_file + +- name: Copy requirements file to temporary location + copy: + src: requirements.txt + dest: "{{ req_file.path }}" + - name: Ensure Python requirements are installed pip: - requirements: "{{ '/'.join([role_path, 'files', 'requirements.txt']) }}" + requirements: "{{ req_file.path }}" extra_args: >- -c {{ ironic_python_upper_constraints_url }} virtualenv: "{{ ironic_virtualenv_path }}" diff --git a/ansible/roles/virtualbmc-daemon/tasks/main.yml b/ansible/roles/virtualbmc-daemon/tasks/main.yml index 937d90f..1071e17 100644 --- a/ansible/roles/virtualbmc-daemon/tasks/main.yml +++ b/ansible/roles/virtualbmc-daemon/tasks/main.yml @@ -6,9 +6,19 @@ loop: "{{ vbmcd_packages }}" become: true +# This is useful to get a uniquely generated temporary path. +- name: Create temporary file for pip requirements + tempfile: + register: req_file + +- name: Copy requirements file to temporary location + copy: + src: requirements.txt + dest: "{{ req_file.path }}" + - name: Ensure Python requirements are installed pip: - requirements: "{{ '/'.join([role_path, 'files', 'requirements.txt']) }}" + requirements: "{{ req_file.path }}" extra_args: >- -c {{ vbmcd_python_upper_constraints_url }} virtualenv: "{{ vbmcd_virtualenv_path }}"