<feed xmlns='http://www.w3.org/2005/Atom'>
<title>vyos-cloud-init.git/tests/unittests/sources/test_azure.py, branch rolling</title>
<subtitle> (mirror of https://github.com/vyos/vyos-cloud-init.git)
</subtitle>
<id>https://git.amelek.net/vyos/vyos-cloud-init.git/atom?h=rolling</id>
<link rel='self' href='https://git.amelek.net/vyos/vyos-cloud-init.git/atom?h=rolling'/>
<link rel='alternate' type='text/html' href='https://git.amelek.net/vyos/vyos-cloud-init.git/'/>
<updated>2022-02-15T17:19:19+00:00</updated>
<entry>
<title>sources/azure: report ready in local phase (#1265)</title>
<updated>2022-02-15T17:19:19+00:00</updated>
<author>
<name>Chris Patterson</name>
<email>cpatterson@microsoft.com</email>
</author>
<published>2022-02-15T17:19:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.amelek.net/vyos/vyos-cloud-init.git/commit/?id=101a62f2389a933676e9d0d20d9f59303b1f1833'/>
<id>urn:sha1:101a62f2389a933676e9d0d20d9f59303b1f1833</id>
<content type='text'>
Pre-provisioned instances report ready early in the local phase and
again in the non-local phase, during setup().  Non-PPS only reports
ready during non-local phase.

Update the process to report ready during the local phase for all
cases.  Only attempt to do so if networking is up to prevent stalling
boot. We've already waited at least 20 minutes for DHCP if we're
provisioning, or 5 minutes for DHCP on normal boot requesting updated
network configuration.

- Extend _report_ready() with pubkey_info and raise exception
  on error to consolidate reporting done in _negotiate() and
  _report_ready().

- Remove setup(), moving relevant logic into crawl_metadata().

- Move remaining _negotiate() logic into _cleanup_markers() and
  _determine_wireserver_pubkey_info().

These changes effectively fix two issues that were present:

(1) _negotiated is incorrectly set to True

When failing to report ready.  _negotiate() squashed the exception and
the return value was not checked.  This was probably masked due to the
forced removal of obj.pkl on Ubuntu instances, but would be preferable
once we start persisting it to prevent unnecessary re-negotiation.

(2) provisioning media is not ejected for non-PPS

_negotiate() did not pass iso_dev parameter when reporting ready.  The
host will ensure this operation takes place, but it is preferable to
eject /dev/sr0 from within the guest when we're done with it.

Lastly, this removes any need for lease file parsing as the wireserver
addressed is tracked for ephemeral DHCP.  A follow-up PR will remove
this now-unused logic.

Signed-off-by: Chris Patterson &lt;cpatterson@microsoft.com&gt;</content>
</entry>
<entry>
<title>sources/azure: validate IMDS network configuration metadata (#1257)</title>
<updated>2022-02-14T19:53:36+00:00</updated>
<author>
<name>Chris Patterson</name>
<email>cpatterson@microsoft.com</email>
</author>
<published>2022-02-14T19:53:36+00:00</published>
<link rel='alternate' type='text/html' href='https://git.amelek.net/vyos/vyos-cloud-init.git/commit/?id=32fcbb580d6eacb06c901bc291e0fa118bb9b646'/>
<id>urn:sha1:32fcbb580d6eacb06c901bc291e0fa118bb9b646</id>
<content type='text'>
Due to race conditions and caching, IMDS may return stale or incomplete
metadata.  Add some validation to detect these scenarios and report
appropriate telemetry.

Introduce normalize_mac_address() to allow for comparison of mac
addresses, replacing that found inline in:
_generate_network_config_from_imds_metadata()

Add validation of final fetch of IMDS metadata.

Signed-off-by: Chris Patterson &lt;cpatterson@microsoft.com&gt;</content>
</entry>
<entry>
<title>sources/azure: address mypy/pyright typing complaints (#1245)</title>
<updated>2022-02-12T04:40:45+00:00</updated>
<author>
<name>Chris Patterson</name>
<email>cpatterson@microsoft.com</email>
</author>
<published>2022-02-12T04:40:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.amelek.net/vyos/vyos-cloud-init.git/commit/?id=0b41b359a70bbbf3a648862a9b849d60b9ff6c3b'/>
<id>urn:sha1:0b41b359a70bbbf3a648862a9b849d60b9ff6c3b</id>
<content type='text'>
Raise runtime errors for unhandled cases which would cause other
exceptions.  Ignore types for a few cases where a non-trivial
refactor would be required to prevent the warning.

Signed-off-by: Chris Patterson &lt;cpatterson@microsoft.com&gt;</content>
</entry>
<entry>
<title>sources/azure: refactor ssh key handling (#1248)</title>
<updated>2022-02-10T20:03:10+00:00</updated>
<author>
<name>Chris Patterson</name>
<email>cpatterson@microsoft.com</email>
</author>
<published>2022-02-10T20:03:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.amelek.net/vyos/vyos-cloud-init.git/commit/?id=50de985bc4e47dff1a8fc52abb7679032bb40cae'/>
<id>urn:sha1:50de985bc4e47dff1a8fc52abb7679032bb40cae</id>
<content type='text'>
Split _get_public_ssh_keys_and_source() into
_get_public_keys_from_imds() and _get_public_keys_from_ovf().

Set _get_public_keys_from_imds() to take a parameter of the
IMDS metadata rather than assuming it is already set in
self.metadata.  This will allow us to move negotation into
local phase where self.metadata may not be set yet.  Update this
method to raise KeyError if IMDS metadata is missing/malformed,
and ValueError if SSH key format is not supported.  Update
get_public_ssh_keys() to catch these errors and fall back to the
OVF/Wireserver keys as needed.

To improve clarity, update register_with_azure_and_fetch_data()
to return the list of SSH keys, rather than bundling them into
a dictionary for updating against the metadata dictionary.

There should be no change in behavior with this refactor.

Signed-off-by: Chris Patterson &lt;cpatterson@microsoft.com&gt;</content>
</entry>
<entry>
<title>sources/azure: consolidate ephemeral DHCP configuration (#1229)</title>
<updated>2022-02-04T20:16:21+00:00</updated>
<author>
<name>Chris Patterson</name>
<email>cpatterson@microsoft.com</email>
</author>
<published>2022-02-04T20:16:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.amelek.net/vyos/vyos-cloud-init.git/commit/?id=826783d83f55b78336cdb9e16ea39a1038618b03'/>
<id>urn:sha1:826783d83f55b78336cdb9e16ea39a1038618b03</id>
<content type='text'>
Introduce:

-  _setup_ephemeral_networking() to bring up networking.
  If no iface is specified, it will use net.find_fallback_nic()
  which is consistent with the previous usage of fallback_interface.
  This method now tracks the encoded address of the wireserver
  with a new property `_wireserver_endpoint`.  Introduce a
  timeout parameter to allow for retrying for a specified amount
  of time.

- _teardown_ephemeral_networking() to bring down networking.

- _is_ephemeral_networking_up() to check status.

Ephemeral networking is now:

- Brought up prior to checking IMDS.

- Torn down following metadata crawl.

- For Savable PPS, torn down prior to waiting for NIC detach.
  The link must be torn down in advance or we will see errors
  from cleaning up network after the interface is unplugged.

- For Running PPS, torn down after waiting for media switch.
  The link must be up for media switch to be detected.

- For all PPS, after network switch is complete, networking is
  brought back up to poll for reprovision data and report ready.
  It will be torn down after metadata crawl is complete like
  non-PPS paths.

Additionally:

- Remove EphemeralDHCPv4WithReporting variant in favor of directly
using EphemeralDHCPv4.  The reporting was only for __enter__ usage
which is no longer a used path.  Continue to use dhcp_log_cb
callback.

Signed-off-by: Chris Patterson &lt;cpatterson@microsoft.com&gt;</content>
</entry>
<entry>
<title>sources/azure: fix metadata check in _check_if_nic_is_primary() (#1232)</title>
<updated>2022-02-04T19:17:38+00:00</updated>
<author>
<name>Chris Patterson</name>
<email>cpatterson@microsoft.com</email>
</author>
<published>2022-02-04T19:17:38+00:00</published>
<link rel='alternate' type='text/html' href='https://git.amelek.net/vyos/vyos-cloud-init.git/commit/?id=6d817e94beb404d3917bf973bcb728aa6cc22ffe'/>
<id>urn:sha1:6d817e94beb404d3917bf973bcb728aa6cc22ffe</id>
<content type='text'>
Currently _check_if_nic_is_primary() checks for imds_md is None,
but imds_md is returned as an empty dictionary on error fetching
metdata.

Fix this check and the tests that are incorrectly vetting IMDS
polling code.

Additionally, use response.contents instead of str(response) when
loding the JSON data returned from readurl.  This helps simplify the
mocking and avoids an unncessary conversion.

Signed-off-by: Chris Patterson &lt;cpatterson@microsoft.com&gt;</content>
</entry>
<entry>
<title>sources/azure: refactor _report_ready_if_needed and _poll_imds (#1222)</title>
<updated>2022-01-31T21:35:10+00:00</updated>
<author>
<name>Chris Patterson</name>
<email>cpatterson@microsoft.com</email>
</author>
<published>2022-01-31T21:35:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.amelek.net/vyos/vyos-cloud-init.git/commit/?id=902aa44e6f4d267b5a7a59abb463f7b22c8d14d8'/>
<id>urn:sha1:902aa44e6f4d267b5a7a59abb463f7b22c8d14d8</id>
<content type='text'>
Refactor _report_ready_if_needed() to work for both Savable PPS
and Runnable PPS:
* rename _report_ready_if_needed() to _report_ready_for_pps()
* return interface name from lease to support _poll_imds() behavior
  without changing it.
* fixes an issue where reporting ready return value was silently
  ignored for Savable PPS.
* add explicit handling for failure to obtain DHCP lease to
  result in sources.InvalidMetaDataException.

Refactor _poll_imds():
* use _report_ready_for_pps() for reporting ready, removing this logic
  to simplify loop logic.
* move netlink and vnetswitch out of while loop to simplify loop logic,
  leaving only reprovision polling in loop.
* add explicit handling for failure to obtain DHCP lease and
  retry in the next iteration.

Signed-off-by: Chris Patterson cpatterson@microsoft.com</content>
</entry>
<entry>
<title>sources/azure: refactor _should_reprovision[_after_nic_attach]() logic (#1206)</title>
<updated>2022-01-28T19:38:22+00:00</updated>
<author>
<name>Chris Patterson</name>
<email>cpatterson@microsoft.com</email>
</author>
<published>2022-01-28T19:38:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.amelek.net/vyos/vyos-cloud-init.git/commit/?id=1b095760b5b7b7d59da12878098de97e3cb9885c'/>
<id>urn:sha1:1b095760b5b7b7d59da12878098de97e3cb9885c</id>
<content type='text'>
Consolidate _should_reprovision_after_nic_attach() with
_should_reprovision() into the following:

_write_reprovision_marker() to write provisioning marker for
reboot-during-provisioning case.

PPSType enum and _determine_pps_type() for determining which to
provisioning mode, if any, we're running under.

PPSType.UNKNOWN is when the reprovisioning marker is found and we
do not have the context to know what the original mode was. In this
scenario, we must resort to polling for reprovision data.

Tests:

Introduce a simple data source fixture to for fine-grain
control of mocking with pytest without unittest.

Migrate relevant _should_reprovision() tests into a combination of
TestDeterminePPSTypeScenarios cases.

Signed-off-by: Chris Patterson cpatterson@microsoft.com</content>
</entry>
<entry>
<title>sources/azure: drop unused case in _report_failure() (#1200)</title>
<updated>2022-01-20T22:46:49+00:00</updated>
<author>
<name>Chris Patterson</name>
<email>cpatterson@microsoft.com</email>
</author>
<published>2022-01-20T22:46:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.amelek.net/vyos/vyos-cloud-init.git/commit/?id=6f0e881847822223fb96925b229322120772fa94'/>
<id>urn:sha1:6f0e881847822223fb96925b229322120772fa94</id>
<content type='text'>
According to the documentation in the tests:

```
We expect 3 calls to report_failure_to_fabric,
because we try 3 different methods of calling report failure.
The different methods are attempted in the following order:
1. Using cached ephemeral dhcp context to report failure to Azure
2. Using new ephemeral dhcp to report failure to Azure
3. Using fallback lease to report failure to Azure
```

Case 1 and 2 make sense.  If networking is established, use it.
Should failure occur using current network configuration, retry
with fresh DHCP.

Case 3 suggests that we can fall back to a lease file and retry.

Given that:

1. The wireserver address has never changed to date.
2. The wireserver address should be in the DHCP lease.
3. Parsing the lease file does not improve connectivity over the
   prior attempts.

...we can safely remove this case without regression.

Signed-off-by: Chris Patterson &lt;cpatterson@microsoft.com&gt;</content>
</entry>
<entry>
<title>sources/azure: unpack ret tuple in crawl_metadata() (#1194)</title>
<updated>2022-01-20T21:34:22+00:00</updated>
<author>
<name>Chris Patterson</name>
<email>cpatterson@microsoft.com</email>
</author>
<published>2022-01-20T21:34:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.amelek.net/vyos/vyos-cloud-init.git/commit/?id=6c8770f5336c8c74dc8208f50ab0a479363d1332'/>
<id>urn:sha1:6c8770f5336c8c74dc8208f50ab0a479363d1332</id>
<content type='text'>
load_azure_ds_dir() always returns a tuple.  Instead of saving this
tuple as ret, expand it immediately as md, userdata_raw, cfg, files.

This allows for more fine-grained passing of data before getting
expanded later.

- Update _should_reprovision methods to use cfg instead of tuple.

- Update _should_reprovision methods to remove the ovf_md guard.
 This should be a safe refactor as the OVF is not required, and the
 config is initialized to an empty dict.  In practice, a mount failure
 would have initialized ret anyways if the OVF was not found. If a
 mount failure wasn't seen and ret was None, this guard could be
 causing other failures by ignoring the PPS state that should be
 available from IMDS metadata.

Signed-off-by: Chris Patterson &lt;cpatterson@microsoft.com&gt;</content>
</entry>
</feed>
