os-brick/os_brick/tests/initiator/connectors
Gorka Eguileor 37d57c4306 NVMe-oF: Return right nqn when missing hostnqn
This patch fixes a problem where we don't return the right nqn value
when the /etc/nvme/hostnqn file doesn't exist.

Currently get_connector_properties returns a new nqn value every time it
gets called if the hostnqn file is not present in the system.

The reason for this is that we are calling "nvme gen-hostnqn" and piping
it to tee, but for some reason tee is failing to write the file, so on
each call we'll generate a new nqn.

Even if we were successfully creating the hostnqn file, that could
create problems if we have already attached some volumes, since those
would have used the existing nqn.

This patch replaces the series of command executions (mkdir, nvme,
chmod) with a privsep method that then leverages the equivalent python
methods when possible and also tries to use the show-hostnqn nvme
subcommand first to get the existing nqn before defaulting to generating
a new one with gen-hostnqn.  This way we don't replace the current nqn
value that may be already being used by other nvme connections.

Subcommand show-hostnqn returns the host NQN configured for the system.
First looks for /etc/nvme/hostnqn, if it's not present (our case when we
call the new create_hostnqn method) tries to construct it from dmi
(/sys/firmware/dmi/entries) or from systemd's application-specific
machine IDs for the system [1].

It's important to differentiate between the ENOENT returned as OSError
and the same value returned by nvme [2] when show-hostnqn cannot return
anything.

[1]: ed9538622a/fabrics.c (L858-L875)
[2]: 5b8b065b1d/nvme.c (L5642-L5643)

Closes-Bug: #1928944
Change-Id: I252dd958767dcdd4f9a2767b362aaf675edb79c4
2021-06-07 16:04:28 +02:00
..
__init__.py Splitting Out Connectors from connector.py 2016-08-02 15:54:15 -05:00
test_base_iscsi.py iSCSI: Fix flushing after multipath cfg change 2021-03-26 11:07:45 +01:00
test_base_rbd.py rbd Windows support 2020-12-09 20:50:24 +02:00
test_fibre_channel.py Merge "Remove six" 2021-03-04 00:52:17 +00:00
test_fibre_channel_ppc64.py Use unittest.mock instead of third party mock 2020-04-18 16:22:50 -05:00
test_fibre_channel_s390x.py Merge "prepend platform info to by-path string" 2020-08-06 22:48:29 +00:00
test_gpfs.py Add connector for GPFS volumes 2016-08-16 16:09:52 +05:30
test_huawei.py Use unittest.mock instead of third party mock 2020-04-18 16:22:50 -05:00
test_iscsi.py iSCSI: Fix flushing after multipath cfg change 2021-03-26 11:07:45 +01:00
test_iser.py iSCSI: Fix flushing after multipath cfg change 2021-03-26 11:07:45 +01:00
test_local.py Splitting Out Connectors from connector.py 2016-08-02 15:54:15 -05:00
test_nvmeof.py NVMe-oF: Return right nqn when missing hostnqn 2021-06-07 16:04:28 +02:00
test_rbd.py Move os-brick to new hacking 4.0.0 2021-03-04 13:54:44 -05:00
test_remotefs.py Use unittest.mock instead of third party mock 2020-04-18 16:22:50 -05:00
test_scaleio.py Merge "Fix import order of libraries" 2021-03-04 15:15:32 +00:00
test_storpool.py Use unittest.mock instead of third party mock 2020-04-18 16:22:50 -05:00
test_vmware.py vmware: Use cookiejar from oslo.vmware client directly 2021-04-28 07:58:47 +00:00