Repository: metal3-io/baremetal-operator (go)
Issue: Online attribute should be set to false when creating BMHs
Currently the cmd tool that creates BMH CRs set the "Online" flag to true. This is now causing problems in Metal3-dev-env.

Setting the flag to true causes BMO to power on the nodes after the introspection is completed. However, due to a combination of factors, including blank hard drives, the nodes end up booting again over PXE into IPA. After boot, IPA does a lookup for the node based on the mac address. However, since restrict_lookup is true by default, and the node is in manageable state, Ironic returns 404 (expected). However, IPA interprets it as needing introspection. It then performs introspection and reports to inspector. Inspector then internally fails with the following stack trace because the node is not in the expected state. 

To fix that, (aside of modifying ironic), we can just ensure that the nodes are not powered on after introspection, by setting "Online" to false.

The inspector stack trace is 
```
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main [req-236063ab-920f-46ab-b28c-45ee8bd4f8f7 - - - - -] Internal server error: AttributeError: 'Node' object has no attribute 'uuid'
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main Traceback (most recent call last):
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/ironic_inspector/process.py", line 87, in _find_node_info
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     mac=macs)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/ironic_inspector/node_cache.py", line 819, in find_node
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     'Could not find a node for attributes %s') % attributes)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main ironic_inspector.utils.NotFoundInCacheError: Could not find a node for attributes {'bmc_address': [], 'mac': ['00:0c:44:84:04:29', '00:0c:44:84:04:27']}
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main 
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main During handling of the above exception, another exception occurred:
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main 
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main Traceback (most recent call last):
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/ironic_inspector/main.py", line 130, in wrapper
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     return func(*args, **kwargs)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/ironic_inspector/main.py", line 243, in wrapper
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     return func(*args, **kwargs)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/ironic_inspector/main.py", line 294, in api_continue
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     result = client.call({}, 'do_continue', data=data)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/oslo_messaging/rpc/client.py", line 511, in call
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     return self.prepare().call(ctxt, method, **kwargs)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/oslo_messaging/rpc/client.py", line 181, in call
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     transport_options=self.transport_options)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/oslo_messaging/transport.py", line 129, in _send
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     transport_options=transport_options)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/oslo_messaging/_drivers/impl_fake.py", line 223, in send
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     transport_options)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/oslo_messaging/_drivers/impl_fake.py", line 209, in _send
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     raise failure
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/oslo_messaging/rpc/server.py", line 165, in _process_incoming
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     res = self.dispatcher.dispatch(message)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/oslo_messaging/rpc/dispatcher.py", line 276, in dispatch
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     return self._do_dispatch(endpoint, method, ctxt, args)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/oslo_messaging/rpc/dispatcher.py", line 196, in _do_dispatch
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     result = func(ctxt, **new_args)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/oslo_messaging/rpc/server.py", line 241, in inner
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     return func(*args, **kwargs)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/ironic_inspector/conductor/manager.py", line 190, in do_continue
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     return process.process(data)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/ironic_inspector/process.py", line 206, in process
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     node_info = _find_node_info(introspection_data, failures)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/ironic_inspector/process.py", line 92, in _find_node_info
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     macs=macs)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/ironic_inspector/node_cache.py", line 961, in record_node
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     {'node': node.uuid,
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/openstack/resource.py", line 588, in __getattribute__
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     raise e
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main   File "/usr/lib/python3.6/site-packages/openstack/resource.py", line 582, in __getattribute__
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main     return object.__getattribute__(self, name)
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main AttributeError: 'Node' object has no attribute 'uuid'
2020-07-07 07:02:44.534 1 ERROR ironic_inspector.main 
2020-07-07 07:02:44.535 1 DEBUG ironic_inspector.main [req-236063ab-920f-46ab-b28c-45ee8bd4f8f7 - - - - -] Returning error to client: Internal server error (AttributeError): 'Node' object has no attribute 'uuid' error_response /usr/lib/python3.6/site-packages/ironic_inspector/main.py:122
```
Pull request description: Set Online to false when rendering BMH CRs
Fixes #578 

Patch:
diff --git a/cmd/make-bm-worker/templates/templates.go b/cmd/make-bm-worker/templates/templates.go
index bf51c466..00d16847 100644
--- a/cmd/make-bm-worker/templates/templates.go
+++ b/cmd/make-bm-worker/templates/templates.go
@@ -22,7 +22,7 @@ kind: BareMetalHost
 metadata:
   name: {{ .Name }}
 spec:
-  online: true
+  online: false
 {{- if .HardwareProfile }}
   hardwareProfile: {{ .HardwareProfile }}
 {{- end }}
diff --git a/cmd/make-virt-host/main.go b/cmd/make-virt-host/main.go
index 140382b0..41b86070 100644
--- a/cmd/make-virt-host/main.go
+++ b/cmd/make-virt-host/main.go
@@ -68,7 +68,7 @@ kind: BareMetalHost
 metadata:
   name: {{ .Domain }}
 spec:
-  online: true
+  online: false
   bmc:
     address: libvirt://192.168.122.1:{{ .BMCPort }}/
     credentialsName: {{ .Domain }}-bmc-secret


Test patch:
diff --git a/cmd/make-bm-worker/templates/templates_test.go b/cmd/make-bm-worker/templates/templates_test.go
index 92a6aa32..c3784620 100644
--- a/cmd/make-bm-worker/templates/templates_test.go
+++ b/cmd/make-bm-worker/templates/templates_test.go
@@ -51,7 +51,7 @@ kind: BareMetalHost
 metadata:
   name: hostname
 spec:
-  online: true
+  online: false
   hardwareProfile: hardware profile
   bmc:
     address: bmcAddress
@@ -86,7 +86,7 @@ kind: BareMetalHost
 metadata:
   name: hostname
 spec:
-  online: true
+  online: false
   bmc:
     address: bmcAddress
     credentialsName: hostname-bmc-secret
@@ -122,7 +122,7 @@ kind: BareMetalHost
 metadata:
   name: hostname
 spec:
-  online: true
+  online: false
   bmc:
     address: bmcAddress
     credentialsName: hostname-bmc-secret