From fe05724902167901889514174cbe6646b98045e1 Mon Sep 17 00:00:00 2001 From: Julia Kreger Date: Tue, 24 Mar 2015 12:06:25 -0400 Subject: [PATCH] Adding basic testing of VMs with test-bifrost.yaml Added two roles and appropriate changes to test-bifrost.yaml in order to add the new hosts, typically which should be a single virtual machine, to the running inventory, and then connect to them and verify that the hostname is NOT ubuntu. This is in support of issue #4. --- roles/bifrost-prepare-for-test/README.md | 38 ++++++ .../defaults/main.yml | 2 + .../handlers/main.yml | 2 + roles/bifrost-prepare-for-test/meta/main.yml | 116 ++++++++++++++++++ roles/bifrost-prepare-for-test/tasks/main.yml | 30 +++++ roles/bifrost-prepare-for-test/vars/main.yml | 2 + roles/bifrost-test-vm/README.md | 38 ++++++ roles/bifrost-test-vm/defaults/main.yml | 2 + roles/bifrost-test-vm/handlers/main.yml | 2 + roles/bifrost-test-vm/meta/main.yml | 116 ++++++++++++++++++ roles/bifrost-test-vm/tasks/main.yml | 22 ++++ roles/bifrost-test-vm/vars/main.yml | 2 + test-bifrost.yaml | 10 ++ 13 files changed, 382 insertions(+) create mode 100644 roles/bifrost-prepare-for-test/README.md create mode 100644 roles/bifrost-prepare-for-test/defaults/main.yml create mode 100644 roles/bifrost-prepare-for-test/handlers/main.yml create mode 100644 roles/bifrost-prepare-for-test/meta/main.yml create mode 100644 roles/bifrost-prepare-for-test/tasks/main.yml create mode 100644 roles/bifrost-prepare-for-test/vars/main.yml create mode 100644 roles/bifrost-test-vm/README.md create mode 100644 roles/bifrost-test-vm/defaults/main.yml create mode 100644 roles/bifrost-test-vm/handlers/main.yml create mode 100644 roles/bifrost-test-vm/meta/main.yml create mode 100644 roles/bifrost-test-vm/tasks/main.yml create mode 100644 roles/bifrost-test-vm/vars/main.yml diff --git a/roles/bifrost-prepare-for-test/README.md b/roles/bifrost-prepare-for-test/README.md new file mode 100644 index 000000000..225dd44b9 --- /dev/null +++ b/roles/bifrost-prepare-for-test/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/bifrost-prepare-for-test/defaults/main.yml b/roles/bifrost-prepare-for-test/defaults/main.yml new file mode 100644 index 000000000..18feb30f5 --- /dev/null +++ b/roles/bifrost-prepare-for-test/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for bifrost-prepare-for-test diff --git a/roles/bifrost-prepare-for-test/handlers/main.yml b/roles/bifrost-prepare-for-test/handlers/main.yml new file mode 100644 index 000000000..2854357d2 --- /dev/null +++ b/roles/bifrost-prepare-for-test/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for bifrost-prepare-for-test diff --git a/roles/bifrost-prepare-for-test/meta/main.yml b/roles/bifrost-prepare-for-test/meta/main.yml new file mode 100644 index 000000000..103a741d5 --- /dev/null +++ b/roles/bifrost-prepare-for-test/meta/main.yml @@ -0,0 +1,116 @@ +--- +galaxy_info: + author: Ironic Developers + description: Prepare for basic bifrost testing. + company: OpenStack + license: Apache + min_ansible_version: 1.9 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + - trusty + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + categories: + - cloud + - cloud:openstack + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] diff --git a/roles/bifrost-prepare-for-test/tasks/main.yml b/roles/bifrost-prepare-for-test/tasks/main.yml new file mode 100644 index 000000000..0c4f40146 --- /dev/null +++ b/roles/bifrost-prepare-for-test/tasks/main.yml @@ -0,0 +1,30 @@ +# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +--- +- name: "Waiting for the base testvm machine to become available." + wait_for: state=started port=22 host={{ item.split(',')[11] }} timeout=600 + with_lines: + - cat {{ baremetal_csv_file }} +- name: "Adding testvms to Ansible Inventory" + add_host: name="{{ item.split(',')[11] }}:22" groups=testvm + with_lines: + - cat {{ baremetal_csv_file }} +- name: "Removing testvm hosts from ssh known_hosts file." + command: ssh-keygen -R "{{ item.split(',')[11] }}" + with_lines: + - cat {{ baremetal_csv_file }} +- name: "Adding testvm hosts from ssh known_hosts file." + shell: ssh-keyscan "{{ item.split(',')[11] }}" >> "{{ ansible_env.HOME }}/.ssh/known_hosts" + with_lines: + - cat {{ baremetal_csv_file }} diff --git a/roles/bifrost-prepare-for-test/vars/main.yml b/roles/bifrost-prepare-for-test/vars/main.yml new file mode 100644 index 000000000..1391ec7c3 --- /dev/null +++ b/roles/bifrost-prepare-for-test/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for bifrost-prepare-for-test diff --git a/roles/bifrost-test-vm/README.md b/roles/bifrost-test-vm/README.md new file mode 100644 index 000000000..225dd44b9 --- /dev/null +++ b/roles/bifrost-test-vm/README.md @@ -0,0 +1,38 @@ +Role Name +========= + +A brief description of the role goes here. + +Requirements +------------ + +Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required. + +Role Variables +-------------- + +A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well. + +Dependencies +------------ + +A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles. + +Example Playbook +---------------- + +Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too: + + - hosts: servers + roles: + - { role: username.rolename, x: 42 } + +License +------- + +BSD + +Author Information +------------------ + +An optional section for the role authors to include contact information, or a website (HTML is not allowed). diff --git a/roles/bifrost-test-vm/defaults/main.yml b/roles/bifrost-test-vm/defaults/main.yml new file mode 100644 index 000000000..df15a33e4 --- /dev/null +++ b/roles/bifrost-test-vm/defaults/main.yml @@ -0,0 +1,2 @@ +--- +# defaults file for bifrost-test-vm diff --git a/roles/bifrost-test-vm/handlers/main.yml b/roles/bifrost-test-vm/handlers/main.yml new file mode 100644 index 000000000..b00700daa --- /dev/null +++ b/roles/bifrost-test-vm/handlers/main.yml @@ -0,0 +1,2 @@ +--- +# handlers file for bifrost-test-vm diff --git a/roles/bifrost-test-vm/meta/main.yml b/roles/bifrost-test-vm/meta/main.yml new file mode 100644 index 000000000..efd873f0f --- /dev/null +++ b/roles/bifrost-test-vm/meta/main.yml @@ -0,0 +1,116 @@ +--- +galaxy_info: + author: Ironic Developers + description: Basic connectivity test. + company: OpenStack + license: Apache + min_ansible_version: 1.9 + # + # Below are all platforms currently available. Just uncomment + # the ones that apply to your role. If you don't see your + # platform on this list, let us know and we'll get it added! + # + platforms: + #- name: EL + # versions: + # - all + # - 5 + # - 6 + # - 7 + #- name: GenericUNIX + # versions: + # - all + # - any + #- name: Fedora + # versions: + # - all + # - 16 + # - 17 + # - 18 + # - 19 + # - 20 + #- name: SmartOS + # versions: + # - all + # - any + #- name: opensuse + # versions: + # - all + # - 12.1 + # - 12.2 + # - 12.3 + # - 13.1 + # - 13.2 + #- name: Amazon + # versions: + # - all + # - 2013.03 + # - 2013.09 + #- name: GenericBSD + # versions: + # - all + # - any + #- name: FreeBSD + # versions: + # - all + # - 8.0 + # - 8.1 + # - 8.2 + # - 8.3 + # - 8.4 + # - 9.0 + # - 9.1 + # - 9.1 + # - 9.2 + #- name: Ubuntu + # versions: + # - all + # - lucid + # - maverick + # - natty + # - oneiric + # - precise + # - quantal + # - raring + # - saucy + - trusty + #- name: SLES + # versions: + # - all + # - 10SP3 + # - 10SP4 + # - 11 + # - 11SP1 + # - 11SP2 + # - 11SP3 + #- name: GenericLinux + # versions: + # - all + # - any + #- name: Debian + # versions: + # - all + # - etch + # - lenny + # - squeeze + # - wheezy + # + # Below are all categories currently available. Just as with + # the platforms above, uncomment those that apply to your role. + # + categories: + - cloud + - cloud:openstack + #- cloud:gce + #- cloud:rax + #- clustering + #- database + #- database:nosql + #- database:sql + #- development + #- monitoring + #- networking + #- packaging + #- system + #- web +dependencies: [] diff --git a/roles/bifrost-test-vm/tasks/main.yml b/roles/bifrost-test-vm/tasks/main.yml new file mode 100644 index 000000000..d2ca20c9e --- /dev/null +++ b/roles/bifrost-test-vm/tasks/main.yml @@ -0,0 +1,22 @@ +# Copyright (c) 2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +--- +- name: "Execute ping step to verify connectivity and login to the host. If this fails, the configdrive may not have loaded." + ping: +- name: 'Error if hostname is set to "ubuntu"' + # TODO: Presently this step is unable to cycle through each host and verify it's hostname is properly set. + # Perhaps if there was some way to extract the data on each host from Ironic's DB and then verify that information + # as a host-level fact that can be verified. + fail: msg='If this fails, the configdrive may not have been used as the hostname was set to the default "ubuntu"' + when: ansible_hostname == "ubuntu" diff --git a/roles/bifrost-test-vm/vars/main.yml b/roles/bifrost-test-vm/vars/main.yml new file mode 100644 index 000000000..2c2e20b68 --- /dev/null +++ b/roles/bifrost-test-vm/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for bifrost-test-vm diff --git a/test-bifrost.yaml b/test-bifrost.yaml index cd7ef21b2..639009f67 100644 --- a/test-bifrost.yaml +++ b/test-bifrost.yaml @@ -34,3 +34,13 @@ roles: - role: bifrost-configdrives - role: bifrost-setup-nodes + - role: bifrost-prepare-for-test +# The testvm Host group is added by bifrost-prepare-for-test based +# on the contents of the CSV file. +- hosts: testvm + name: "Executes install, enrollment, and testing in one playbook" + sudo: no + gather_facts: yes + remote_user: ubuntu + roles: + - role: bifrost-test-vm