From f3c0526c092760d6c08c244679a0fc47f7e6b821 Mon Sep 17 00:00:00 2001
From: Pierre Riteau <pierre@stackhpc.com>
Date: Wed, 27 Jan 2021 11:00:36 +0100
Subject: [PATCH] Adapt to changes from the Bifrost Victoria release

The critical part of this commit is adapting code that was still
sourcing env-vars. This file was removed from Bifrost in the Victoria
release, breaking the `kayobe seed deployment image build` command.

The other changes are not yet breaking Kayobe:

1) Release notes claim that OpenStackClient is no longer installed when
   keystone is not enabled, but it appears to still be available. Use
   the ironic native baremetal command instead except in playbooks
   related to baremetal compute nodes (i.e. overcloud ironic).

2) The use of OS_CLOUD=bifrost-inspector is deprecated and should be
   replaced by OS_CLOUD=bifrost.

Change-Id: I25078e69acdf41a4ef9957f99fe5047de54b778d
Story: 2008558
Task: 41696
---
 ansible/overcloud-bios-raid.yml               |  4 ++--
 ansible/overcloud-deprovision.yml             |  6 +++---
 ansible/overcloud-hardware-inspect.yml        |  8 ++++----
 ansible/overcloud-introspection-data-save.yml |  2 +-
 ansible/overcloud-provision.yml               |  8 ++++----
 .../roles/dell-switch-bmp/handlers/main.yml   |  6 +++---
 ansible/seed-ipa-build.yml                    |  2 +-
 doc/source/administration/seed.rst            | 15 +++++----------
 doc/source/deployment.rst                     |  8 ++++----
 doc/source/upgrading.rst                      |  9 ++++-----
 ...frost-victoria-fixes-eed49b088afdac5b.yaml | 19 +++++++++++++++++++
 11 files changed, 50 insertions(+), 37 deletions(-)
 create mode 100644 releasenotes/notes/bifrost-victoria-fixes-eed49b088afdac5b.yaml

diff --git a/ansible/overcloud-bios-raid.yml b/ansible/overcloud-bios-raid.yml
index a8b488cd..82d344da 100644
--- a/ansible/overcloud-bios-raid.yml
+++ b/ansible/overcloud-bios-raid.yml
@@ -77,7 +77,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node maintenance set {% raw %}{{ inventory_hostname }}{% endraw %} --reason BIOS-RAID"'
+        -a "baremetal node maintenance set {% raw %}{{ inventory_hostname }}{% endraw %} --reason BIOS-RAID"'
       delegate_to: "{{ seed_host }}"
       vars:
         # NOTE: Without this, the seed's ansible_host variable will not be
@@ -108,7 +108,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node maintenance unset {% raw %}{{ inventory_hostname }}{% endraw %}"'
+        -a "baremetal node maintenance unset {% raw %}{{ inventory_hostname }}{% endraw %}"'
       delegate_to: "{{ seed_host }}"
       vars:
         # NOTE: Without this, the seed's ansible_host variable will not be
diff --git a/ansible/overcloud-deprovision.yml b/ansible/overcloud-deprovision.yml
index f9884622..e907508e 100644
--- a/ansible/overcloud-deprovision.yml
+++ b/ansible/overcloud-deprovision.yml
@@ -45,7 +45,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
+        -a "baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
       register: show_result
       changed_when: False
       delegate_to: "{{ seed_host }}"
@@ -79,7 +79,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node undeploy {% raw %}{{ inventory_hostname }}{% endraw %}"'
+        -a "baremetal node undeploy {% raw %}{{ inventory_hostname }}{% endraw %}"'
       register: delete_result
       until: delete_result is successful or 'is locked by host' in delete_result.stdout
       retries: "{{ ironic_retries }}"
@@ -105,7 +105,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
+        -a "baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
       register: show_result
       # Wait until the node is no longer in one of the deleting states.
       until: not show_result.stdout_lines[1:] | intersect(deleting_states)
diff --git a/ansible/overcloud-hardware-inspect.yml b/ansible/overcloud-hardware-inspect.yml
index 7cd0d8a0..e784f201 100644
--- a/ansible/overcloud-hardware-inspect.yml
+++ b/ansible/overcloud-hardware-inspect.yml
@@ -39,7 +39,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
+        -a "baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
       register: show_result
       changed_when: False
       delegate_to: "{{ seed_host }}"
@@ -73,7 +73,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node manage {% raw %}{{ inventory_hostname }}{% endraw %}"'
+        -a "baremetal node manage {% raw %}{{ inventory_hostname }}{% endraw %}"'
       register: manage_result
       until: manage_result is successful or 'is locked by host' in manage_result.stdout
       retries: "{{ ironic_retries }}"
@@ -98,7 +98,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node inspect {% raw %}{{ inventory_hostname }}{% endraw %}"'
+        -a "baremetal node inspect {% raw %}{{ inventory_hostname }}{% endraw %}"'
       register: provide_result
       until: provide_result is successful or 'is locked by host' in provide_result.stdout
       retries: "{{ ironic_retries }}"
@@ -122,7 +122,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
+        -a "baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
       register: show_result
       # Wait until the node is no longer in one of the inspecting states.
       until: not show_result.stdout_lines[1:] | intersect(inspecting_states)
diff --git a/ansible/overcloud-introspection-data-save.yml b/ansible/overcloud-introspection-data-save.yml
index 2cd80bc2..da2b27c7 100644
--- a/ansible/overcloud-introspection-data-save.yml
+++ b/ansible/overcloud-introspection-data-save.yml
@@ -21,7 +21,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m shell
-        -a "env OS_CLOUD=bifrost-inspector openstack baremetal introspection data save {% raw %}{{ inventory_hostname }}{% endraw %}"'
+        -a "env OS_CLOUD=bifrost baremetal introspection data save {% raw %}{{ inventory_hostname }}{% endraw %}"'
       register: save_result
       changed_when: False
       # Ignore errors, log a message later.
diff --git a/ansible/overcloud-provision.yml b/ansible/overcloud-provision.yml
index afe341ac..7ad3647c 100644
--- a/ansible/overcloud-provision.yml
+++ b/ansible/overcloud-provision.yml
@@ -48,7 +48,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
+        -a "baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
       register: show_result
       changed_when: False
       delegate_to: "{{ seed_host }}"
@@ -82,7 +82,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node manage {% raw %}{{ inventory_hostname }}{% endraw %}"'
+        -a "baremetal node manage {% raw %}{{ inventory_hostname }}{% endraw %}"'
       register: manage_result
       until: manage_result is successful or 'is locked by host' in manage_result.stdout
       retries: "{{ ironic_retries }}"
@@ -107,7 +107,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node provide {% raw %}{{ inventory_hostname }}{% endraw %}"'
+        -a "baremetal node provide {% raw %}{{ inventory_hostname }}{% endraw %}"'
       register: provide_result
       until: provide_result is successful or 'is locked by host' in provide_result.stdout
       retries: "{{ ironic_retries }}"
@@ -163,7 +163,7 @@
         -e @/etc/bifrost/dib.yml
         --limit {{ inventory_hostname }}
         -m command
-        -a "openstack baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
+        -a "baremetal node show {% raw %}{{ inventory_hostname }}{% endraw %} -f value -c provision_state"'
       register: show_result
       # Wait until the node is no longer in one of the deploying states.
       until: not show_result.stdout_lines[1:] | intersect(deploying_states)
diff --git a/ansible/roles/dell-switch-bmp/handlers/main.yml b/ansible/roles/dell-switch-bmp/handlers/main.yml
index d06ba609..be549f9c 100644
--- a/ansible/roles/dell-switch-bmp/handlers/main.yml
+++ b/ansible/roles/dell-switch-bmp/handlers/main.yml
@@ -2,7 +2,7 @@
 - name: Copy dnsmasq configuration
   command: >
     docker exec bifrost_deploy
-    bash -c '. /bifrost/env-vars &&
+    bash -c 'export OS_CLOUD=bifrost &&
     ansible -vvvv target -i /bifrost/playbooks/inventory/target
     -m copy
     -a "src=/etc/bifrost/dell-switch-bmp.conf dest=/etc/dnsmasq.d/dell-switch-bmp.conf"
@@ -11,7 +11,7 @@
 - name: Restart bifrost dnsmasq
   command: >
     docker exec bifrost_deploy
-    bash -c '. /bifrost/env-vars &&
+    bash -c 'export OS_CLOUD=bifrost &&
     ansible -vvvv target -i /bifrost/playbooks/inventory/target
     -m service
     -a "name=dnsmasq state=restarted"
@@ -20,7 +20,7 @@
 - name: Copy Dell switch BMP images
   command: >
     docker exec bifrost_deploy
-    bash -c '. /bifrost/env-vars &&
+    bash -c 'export OS_CLOUD=bifrost &&
     ansible -vvvv target -i /bifrost/playbooks/inventory/target
     -m copy
     -a "src=/etc/bifrost/{{ item.dest }} dest={{ dell_switch_bmp_httpboot_path }}/{{ item.dest }}"
diff --git a/ansible/seed-ipa-build.yml b/ansible/seed-ipa-build.yml
index c9c538a1..ddc3ce50 100644
--- a/ansible/seed-ipa-build.yml
+++ b/ansible/seed-ipa-build.yml
@@ -45,7 +45,7 @@
         - name: Copy Ironic Python Agent images into /httpboot
           command: >
             docker exec bifrost_deploy
-            bash -c '. /bifrost/env-vars &&
+            bash -c 'export OS_CLOUD=bifrost &&
             ansible -vvvv target -i /bifrost/playbooks/inventory/target
             -m copy
             -a "src=/etc/bifrost/{{ item }} dest=/httpboot/{{ item }}"
diff --git a/doc/source/administration/seed.rst b/doc/source/administration/seed.rst
index 84b66513..8ac64ae4 100644
--- a/doc/source/administration/seed.rst
+++ b/doc/source/administration/seed.rst
@@ -79,17 +79,12 @@ Docker volume.
 Accessing the Seed Services
 ===========================
 
-The Ironic API can be accessed via the ``openstack`` command line interface::
+The Ironic and Ironic inspector APIs can be accessed via the ``baremetal``
+command line interface::
 
-    (bifrost_deploy) $ source env-vars
-    (bifrost_deploy) $ openstack baremetal node list
-
-Ironic inspector API requires some environment variables to be set::
-
-    (bifrost_deploy) $ unset OS_CLOUD
-    (bifrost_deploy) $ export OS_URL=http://localhost:5050
-    (bifrost_deploy) $ export OS_TOKEN=fake-token
-    (bifrost_deploy) $ openstack baremetal introspection list
+    (bifrost_deploy) $ export OS_CLOUD=bifrost
+    (bifrost_deploy) $ baremetal node list
+    (bifrost_deploy) $ baremetal introspection list
 
 Backup & Restore
 ================
diff --git a/doc/source/deployment.rst b/doc/source/deployment.rst
index 3a352baa..d49f600c 100644
--- a/doc/source/deployment.rst
+++ b/doc/source/deployment.rst
@@ -266,8 +266,8 @@ registered with the ironic service running in the seed host's
 the following on the seed::
 
     $ docker exec -it bifrost_deploy bash
-    (bifrost_deploy) $ source env-vars
-    (bifrost_deploy) $ openstack baremetal node list
+    (bifrost_deploy) $ export OS_CLOUD=bifrost
+    (bifrost_deploy) $ baremetal node list
 
 In order to interact with these nodes using Kayobe, run the following command
 to add them to the Kayobe and Kolla-Ansible inventories::
@@ -340,8 +340,8 @@ Provisioning
    manually, e.g. from the seed::
 
        $ docker exec -it bifrost_deploy bash
-       (bifrost_deploy) $ source env-vars
-       (bifrost_deploy) $ openstack baremetal node set ee77b4ca-8860-4003-a18f-b00d01295bda --name controller0
+       (bifrost_deploy) $ export OS_CLOUD=bifrost
+       (bifrost_deploy) $ baremetal node set ee77b4ca-8860-4003-a18f-b00d01295bda --name controller0
 
 Provisioning of the overcloud is performed by the ironic service running in the
 bifrost container on the seed.  To provision the overcloud nodes::
diff --git a/doc/source/upgrading.rst b/doc/source/upgrading.rst
index 1ee05c07..7a0b737b 100644
--- a/doc/source/upgrading.rst
+++ b/doc/source/upgrading.rst
@@ -280,11 +280,10 @@ migrate:
 .. code-block:: console
 
    $ docker exec -it bifrost_deploy bash
-   (bifrost_deploy) $ export OS_URL=http://localhost:6385
-   (bifrost_deploy) $ export OS_TOKEN=fake
-   (bifrost_deploy) $ openstack baremetal node maintenance set <node>
-   (bifrost_deploy) $ openstack baremetal node set <node> --driver ipmi
-   (bifrost_deploy) $ openstack baremetal node maintenance unset <node>
+   (bifrost_deploy) $ export OS_CLOUD=bifrost
+   (bifrost_deploy) $ baremetal node maintenance set <node>
+   (bifrost_deploy) $ baremetal node set <node> --driver ipmi
+   (bifrost_deploy) $ baremetal node maintenance unset <node>
 
 Upgrading Containerised Services
 --------------------------------
diff --git a/releasenotes/notes/bifrost-victoria-fixes-eed49b088afdac5b.yaml b/releasenotes/notes/bifrost-victoria-fixes-eed49b088afdac5b.yaml
new file mode 100644
index 00000000..85aef760
--- /dev/null
+++ b/releasenotes/notes/bifrost-victoria-fixes-eed49b088afdac5b.yaml
@@ -0,0 +1,19 @@
+---
+upgrade:
+  - |
+    When interacting with Bifrost, sourcing the ``env-vars`` file is not
+    supported anymore. Set the ``OS_CLOUD`` environment variable to ``bifrost``
+    instead or run ``. ~/openrc bifrost``.
+  - |
+    When interacting with Bifrost, it is recommended to use the ironic native
+    ``baremetal`` command instead of ``openstack baremetal``, as the
+    availability of OpenStackClient inside the Bifrost container is not
+    guaranteed.
+deprecations:
+  - |
+    When interacting with Bifrost, the use of ``OS_CLOUD=bifrost-inspector`` is
+    deprecated and should be replaced by ``OS_CLOUD=bifrost``.
+fixes:
+  - |
+    Fixes failure in the ``kayobe seed deployment image build`` command due to
+    changes in Bifrost.
-- 
GitLab