Merge branch 'master' into resource-classes

Conflicts:
	ansible/action_plugins/tenks_schedule.py
This commit is contained in:
Will Miller 2018-09-07 14:54:19 +00:00
commit d391312d12
9 changed files with 85 additions and 25 deletions

32
.travis.yml Normal file
View File

@ -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}

View File

@ -42,11 +42,13 @@ 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 spec in task_vars['specs']:
try:
typ = spec['type']
@ -55,13 +57,12 @@ class ActionModule(ActionBase):
e = ("All specs must contain a `type` and a `count`. "
"Offending spec: %s" % spec)
raise AnsibleActionFail(to_text(e))
for _ in six.moves.range(cnt):
node = deepcopy(task_vars['node_types'][typ])
# All nodes need an Ironic driver.
node.setdefault('ironic_driver',
task_vars['hostvars']['localhost'][
'default_ironic_driver'])
'default_ironic_driver'])
# Set the type, for future reference.
node['type'] = typ
# Sequentially number the node and volume names.
@ -74,13 +75,15 @@ class ActionModule(ActionBase):
except KeyError:
# Ironic config is not mandatory.
pass
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):

View File

@ -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 }}

9
ansible/group_vars/all Normal file
View File

@ -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

View File

@ -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).

View File

@ -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
@ -69,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:
@ -79,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

View File

@ -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 }}"

View File

@ -6,11 +6,21 @@
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_contraints_url }}
-c {{ vbmcd_python_upper_constraints_url }}
virtualenv: "{{ vbmcd_virtualenv_path }}"
- name: Ensure Virtual BMC systemd service is configured

View File

@ -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