merge: branch 'lr/oci-vm-new-conn'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2180
This commit is contained in:
Lubomir Rintel
2025-04-11 12:09:49 +02:00
8 changed files with 1815 additions and 1614 deletions

View File

@@ -387,17 +387,6 @@ _nmc_skip_connection_by_user_data(NMConnection *connection)
return FALSE;
}
static gboolean
_nmc_skip_connection_by_type(NMConnection *connection, const char *connection_type)
{
if (!nm_streq0(nm_connection_get_connection_type(connection), connection_type))
return TRUE;
if (!nm_connection_get_setting_ip4_config(connection))
return TRUE;
return FALSE;
}
static void
_nmc_mangle_connection(NMDevice *device,
NMConnection *connection,
@@ -618,8 +607,14 @@ try_again:
return any_changes;
}
if (_nmc_skip_connection_by_type(applied_connection, connection_type)) {
_LOGD("config device %s: device has no suitable applied connection. Skip", hwaddr);
if (!nm_streq0(nm_connection_get_connection_type(applied_connection), connection_type)) {
_LOGD("config device %s: skip applied connection due to type mismatch", hwaddr);
return any_changes;
}
if (!nm_connection_get_setting_ip4_config(applied_connection)) {
_LOGD("config device %s: skip applied connection due to missing IPv4 configuration",
hwaddr);
return any_changes;
}
@@ -696,13 +691,34 @@ try_again:
return TRUE;
}
static NMConnection *
_new_connection(void)
{
NMConnection *connection;
NMSetting *s_user;
connection = nm_simple_connection_new();
s_user = nm_setting_user_new();
nm_connection_add_setting(connection, s_user);
nm_setting_user_set_data(NM_SETTING_USER(s_user),
"org.freedesktop.NetworkManager.origin",
"nm-cloud-setup",
NULL);
return connection;
}
static gboolean
_config_ethernet(SigTermData *sigterm_data,
const NMCSProviderGetConfigIfaceData *config_data,
NMClient *nmc,
const NMCSProviderGetConfigResult *result)
const NMCSProviderGetConfigResult *result,
gboolean allow_new_connections)
{
gs_unref_object NMDevice *device = NULL;
gs_unref_object NMConnection *connection = NULL;
gs_unref_object NMActiveConnection *active_connection = NULL;
gs_free_error GError *error = NULL;
device = nm_g_object_ref(
_nmc_get_device_by_hwaddr(nmc, NM_TYPE_DEVICE_ETHERNET, config_data->hwaddr));
@@ -711,12 +727,52 @@ _config_ethernet(SigTermData *sigterm_data,
return FALSE;
}
if (allow_new_connections && nm_device_get_state(device) == NM_DEVICE_STATE_DISCONNECTED) {
connection = _new_connection();
nm_connection_add_setting(connection,
g_object_new(NM_TYPE_SETTING_CONNECTION,
NM_SETTING_CONNECTION_TYPE,
NM_SETTING_WIRED_SETTING_NAME,
NULL));
nm_connection_add_setting(connection,
g_object_new(NM_TYPE_SETTING_IP4_CONFIG,
NM_SETTING_IP_CONFIG_METHOD,
NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
NULL));
nm_connection_add_setting(connection,
g_object_new(NM_TYPE_SETTING_WIRED,
NM_SETTING_WIRED_MAC_ADDRESS,
config_data->hwaddr,
NULL));
_nmc_mangle_connection(device, connection, result, config_data, NULL, NULL);
active_connection = nmcs_add_and_activate(nmc, NULL, device, connection, &error);
if (!active_connection) {
if (!nm_utils_error_is_cancelled(error)) {
_LOGD("config device %s: failure to activate connection: %s",
nm_device_get_iface(NM_DEVICE(device)),
error->message);
}
return FALSE;
}
_LOGD("config device %s: connection \"%s\" (%s) created",
nm_device_get_iface(NM_DEVICE(device)),
nm_active_connection_get_id(active_connection),
nm_active_connection_get_uuid(active_connection));
return TRUE;
} else {
return _config_existing(sigterm_data,
config_data,
nmc,
result,
NM_SETTING_WIRED_SETTING_NAME,
device);
}
}
static gboolean
@@ -738,9 +794,8 @@ _oci_new_vlan_dev(SigTermData *sigterm_data,
const char *wired_mac_addr = NULL;
const NMUtilsNamedValue *map = NULL;
const char *ip4_config_method;
NMSetting *s_user;
connection = nm_simple_connection_new();
connection = _new_connection();
macvlan_name = g_strdup_printf("macvlan%ld", config_data->iface_idx);
connection_id = g_strdup_printf("%s%ld", connection_type, config_data->iface_idx);
@@ -811,13 +866,6 @@ _oci_new_vlan_dev(SigTermData *sigterm_data,
hwaddr,
NULL));
s_user = nm_setting_user_new();
nm_connection_add_setting(connection, s_user);
nm_setting_user_set_data(NM_SETTING_USER(s_user),
"org.freedesktop.NetworkManager.origin",
"nm-cloud-setup",
NULL);
_nmc_mangle_connection(NULL, connection, result, config_data, NULL, NULL);
_LOGD("config device %s: creating %s connection for VLAN %d on %s...",
@@ -826,7 +874,7 @@ _oci_new_vlan_dev(SigTermData *sigterm_data,
config_data->priv.oci.vlan_tag,
parent_hwaddr);
active_connection = nmcs_add_and_activate(nmc, NULL, connection, &error);
active_connection = nmcs_add_and_activate(nmc, NULL, NULL, connection, &error);
if (active_connection == NULL) {
if (!nm_utils_error_is_cancelled(error)) {
_LOGD("config device %s: failure to activate connection: %s", hwaddr, error->message);
@@ -877,6 +925,7 @@ _config_one(SigTermData *sigterm_data,
guint idx)
{
const NMCSProviderGetConfigIfaceData *config_data = result->iface_datas_arr[idx];
gboolean allow_new_connections;
gboolean any_changes;
g_main_context_iteration(NULL, FALSE);
@@ -899,7 +948,13 @@ _config_one(SigTermData *sigterm_data,
return FALSE;
}
if (NMCS_IS_PROVIDER_OCI(provider) && config_data->priv.oci.vlan_tag != 0) {
/* Default on on OCI, with an environment variable serving as a chicken bit. */
allow_new_connections =
_nm_utils_ascii_str_to_bool(g_getenv(NMCS_ENV_NM_CLOUD_SETUP_ALLOW_NEW_CONN),
NMCS_IS_PROVIDER_OCI(provider));
if (allow_new_connections && NMCS_IS_PROVIDER_OCI(provider)
&& config_data->priv.oci.vlan_tag != 0) {
if (config_data->priv.oci.parent_hwaddr == NULL) {
_LOGW("config device %s: has vlan id %d but no parent device",
config_data->hwaddr,
@@ -924,7 +979,8 @@ _config_one(SigTermData *sigterm_data,
config_data->hwaddr);
} else {
any_changes = _config_ethernet(sigterm_data, config_data, nmc, result);
any_changes =
_config_ethernet(sigterm_data, config_data, nmc, result, allow_new_connections);
}
return any_changes;

View File

@@ -637,6 +637,7 @@ _nmcs_add_and_activate_cb(GObject *source, GAsyncResult *result, gpointer user_d
NMActiveConnection *
nmcs_add_and_activate(NMClient *client,
GCancellable *sigterm_cancellable,
NMDevice *device,
NMConnection *connection,
GError **error)
{
@@ -648,7 +649,7 @@ nmcs_add_and_activate(NMClient *client,
nm_client_add_and_activate_connection_async(client,
connection,
NULL,
device,
NULL,
sigterm_cancellable,
_nmcs_add_and_activate_cb,

View File

@@ -23,6 +23,7 @@
#define NMCS_ENV_NM_CLOUD_SETUP_GCP_HOST "NM_CLOUD_SETUP_GCP_HOST"
#define NMCS_ENV_NM_CLOUD_SETUP_OCI_HOST "NM_CLOUD_SETUP_OCI_HOST"
#define NMCS_ENV_NM_CLOUD_SETUP_MAP_INTERFACES "NM_CLOUD_SETUP_MAP_INTERFACES"
#define NMCS_ENV_NM_CLOUD_SETUP_ALLOW_NEW_CONN "NM_CLOUD_SETUP_ALLOW_NEW_CONN"
/*****************************************************************************/
@@ -155,6 +156,7 @@ NMConnection *nmcs_device_get_applied_connection(NMDevice *device,
NMActiveConnection *nmcs_add_and_activate(NMClient *client,
GCancellable *sigterm_cancellable,
NMDevice *device,
NMConnection *connection,
GError **error);

View File

@@ -1,87 +1,89 @@
size: 376
size: 382
location: src/tests/client/test-client.py:test_002()/1
cmd: $NMCLI d
lang: C
returncode: 0
stdout: 258 bytes
stdout: 264 bytes
>>>
DEVICE TYPE STATE CONNECTION
eth0 ethernet unavailable --
eth1 ethernet unavailable --
wlan0 wifi unavailable --
wlan1 wifi unavailable --
wlan1 wifi unavailable --
eth0 ethernet disconnected --
eth1 ethernet disconnected --
wlan0 wifi disconnected --
wlan1 wifi disconnected --
wlan1 wifi disconnected --
<<<
size: 391
size: 390
location: src/tests/client/test-client.py:test_002()/2
cmd: $NMCLI d
lang: pl_PL.UTF-8
returncode: 0
stdout: 263 bytes
stdout: 262 bytes
>>>
DEVICE TYPE STATE CONNECTION
eth0 ethernet niedostępne --
eth1 ethernet niedostępne --
wlan0 wifi niedostępne --
wlan1 wifi niedostępne --
wlan1 wifi niedostępne --
eth0 ethernet rozłączono --
eth1 ethernet rozłączono --
wlan0 wifi rozłączono --
wlan1 wifi rozłączono --
wlan1 wifi rozłączono --
<<<
size: 977
size: 983
location: src/tests/client/test-client.py:test_002()/3
cmd: $NMCLI -f all d
lang: C
returncode: 0
stdout: 852 bytes
stdout: 858 bytes
>>>
DEVICE TYPE STATE IP4-CONNECTIVITY IP6-CONNECTIVITY DBUS-PATH CONNECTION CON-UUID CON-PATH
eth0 ethernet unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/1 -- -- --
eth1 ethernet unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/2 -- -- --
wlan0 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/5 -- -- --
eth0 ethernet disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/1 -- -- --
eth1 ethernet disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/2 -- -- --
wlan0 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/5 -- -- --
<<<
size: 992
size: 991
location: src/tests/client/test-client.py:test_002()/4
cmd: $NMCLI -f all d
lang: pl_PL.UTF-8
returncode: 0
stdout: 857 bytes
stdout: 856 bytes
>>>
DEVICE TYPE STATE IP4-CONNECTIVITY IP6-CONNECTIVITY DBUS-PATH CONNECTION CON-UUID CON-PATH
eth0 ethernet niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/1 -- -- --
eth1 ethernet niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/2 -- -- --
wlan0 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/5 -- -- --
eth0 ethernet rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/1 -- -- --
eth1 ethernet rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/2 -- -- --
wlan0 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/5 -- -- --
<<<
size: 738
size: 791
location: src/tests/client/test-client.py:test_002()/5
cmd: $NMCLI
lang: C
returncode: 0
stdout: 621 bytes
stdout: 674 bytes
>>>
eth0: unavailable
eth0: disconnected
"eth0"
1 connection available
ethernet (virtual), 65:2E:D3:9E:0A:0D, hw
eth1: unavailable
eth1: disconnected
"eth1"
1 connection available
ethernet (virtual), 47:D5:6B:65:FD:6A, hw
wlan0: unavailable
wlan0: disconnected
"wlan0"
wifi (virtual), 3D:99:1D:8B:74:4D, hw
wlan1: unavailable
wlan1: disconnected
"wlan1"
wifi (virtual), 99:09:77:FD:FE:1D, hw
wlan1: unavailable
wlan1: disconnected
"wlan1"
wifi (virtual), 5D:30:4A:EC:3F:61, hw
@@ -94,30 +96,32 @@ Use "nmcli device show" to get complete information about known devices and
Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details.
<<<
size: 811
size: 873
location: src/tests/client/test-client.py:test_002()/6
cmd: $NMCLI
lang: pl_PL.UTF-8
returncode: 0
stdout: 684 bytes
stdout: 746 bytes
>>>
eth0: niedostępne
eth0: rozłączono
"eth0"
1 połączenie jest dostępne
ethernet (virtual), 65:2E:D3:9E:0A:0D, sprzęt
eth1: niedostępne
eth1: rozłączono
"eth1"
1 połączenie jest dostępne
ethernet (virtual), 47:D5:6B:65:FD:6A, sprzęt
wlan0: niedostępne
wlan0: rozłączono
"wlan0"
wifi (virtual), 3D:99:1D:8B:74:4D, sprzęt
wlan1: niedostępne
wlan1: rozłączono
"wlan1"
wifi (virtual), 99:09:77:FD:FE:1D, sprzęt
wlan1: niedostępne
wlan1: rozłączono
"wlan1"
wifi (virtual), 5D:30:4A:EC:3F:61, sprzęt

View File

@@ -1878,34 +1878,34 @@ GENERAL.ZONE: --
GENERAL.MASTER-PATH: --
<<<
size: 1408
size: 1414
location: src/tests/client/test-client.py:test_003()/43
cmd: $NMCLI -f ALL dev status
lang: C
returncode: 0
stdout: 1272 bytes
stdout: 1278 bytes
>>>
DEVICE TYPE STATE IP4-CONNECTIVITY IP6-CONNECTIVITY DBUS-PATH CONNECTION CON-UUID CON-PATH
eth0 ethernet connected unknown unknown /org/freedesktop/NetworkManager/Devices/1 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/1
eth1 ethernet unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/2 -- -- --
wlan0 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/5 -- -- --
eth1 ethernet disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/2 -- -- --
wlan0 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/5 -- -- --
<<<
size: 1424
size: 1422
location: src/tests/client/test-client.py:test_003()/44
cmd: $NMCLI -f ALL dev status
lang: pl_PL.UTF-8
returncode: 0
stdout: 1278 bytes
stdout: 1276 bytes
>>>
DEVICE TYPE STATE IP4-CONNECTIVITY IP6-CONNECTIVITY DBUS-PATH CONNECTION CON-UUID CON-PATH
eth0 ethernet połączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/1 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/1
eth1 ethernet niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/2 -- -- --
wlan0 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/5 -- -- --
eth1 ethernet rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/2 -- -- --
wlan0 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/5 -- -- --
<<<
size: 172
@@ -2974,34 +2974,34 @@ GENERAL.ZONE: --
GENERAL.MASTER-PATH: --
<<<
size: 1408
size: 1414
location: src/tests/client/test-client.py:test_003()/68
cmd: $NMCLI -f ALL dev status
lang: C
returncode: 0
stdout: 1272 bytes
stdout: 1278 bytes
>>>
DEVICE TYPE STATE IP4-CONNECTIVITY IP6-CONNECTIVITY DBUS-PATH CONNECTION CON-UUID CON-PATH
eth0 ethernet connected unknown unknown /org/freedesktop/NetworkManager/Devices/1 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/1
eth1 ethernet connected unknown unknown /org/freedesktop/NetworkManager/Devices/2 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/2
wlan0 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/5 -- -- --
wlan0 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/5 -- -- --
<<<
size: 1425
size: 1422
location: src/tests/client/test-client.py:test_003()/69
cmd: $NMCLI -f ALL dev status
lang: pl_PL.UTF-8
returncode: 0
stdout: 1279 bytes
stdout: 1276 bytes
>>>
DEVICE TYPE STATE IP4-CONNECTIVITY IP6-CONNECTIVITY DBUS-PATH CONNECTION CON-UUID CON-PATH
eth0 ethernet połączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/1 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/1
eth1 ethernet połączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/2 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/2
wlan0 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/5 -- -- --
wlan0 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/5 -- -- --
<<<
size: 172
@@ -3312,42 +3312,42 @@ CONNECTIONS.AVAILABLE-CONNECTIONS[2]:UUID-con-xx1-REPLACED-REPLACED-REPLA | con-
CONNECTIONS.AVAILABLE-CONNECTIONS[3]:UUID-ethernet-REPLACED-REPLACED-REPL | ethernet
<<<
size: 1399
size: 1405
location: src/tests/client/test-client.py:test_003()/76
cmd: $NMCLI -f all d
lang: C
returncode: 0
stdout: 1272 bytes
stdout: 1278 bytes
>>>
DEVICE TYPE STATE IP4-CONNECTIVITY IP6-CONNECTIVITY DBUS-PATH CONNECTION CON-UUID CON-PATH
eth1 ethernet connected unknown unknown /org/freedesktop/NetworkManager/Devices/2 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/2
eth0 ethernet connected unknown unknown /org/freedesktop/NetworkManager/Devices/1 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/1
wlan0 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi unavailable unknown unknown /org/freedesktop/NetworkManager/Devices/5 -- -- --
wlan0 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi disconnected unknown unknown /org/freedesktop/NetworkManager/Devices/5 -- -- --
<<<
size: 1416
size: 1413
location: src/tests/client/test-client.py:test_003()/77
cmd: $NMCLI -f all d
lang: pl_PL.UTF-8
returncode: 0
stdout: 1279 bytes
stdout: 1276 bytes
>>>
DEVICE TYPE STATE IP4-CONNECTIVITY IP6-CONNECTIVITY DBUS-PATH CONNECTION CON-UUID CON-PATH
eth1 ethernet połączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/2 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/2
eth0 ethernet połączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/1 ethernet UUID-ethernet-REPLACED-REPLACED-REPL /org/freedesktop/NetworkManager/ActiveConnection/1
wlan0 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi niedostępne nieznane nieznane /org/freedesktop/NetworkManager/Devices/5 -- -- --
wlan0 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/3 -- -- --
wlan1 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/4 -- -- --
wlan1 wifi rozłączono nieznane nieznane /org/freedesktop/NetworkManager/Devices/5 -- -- --
<<<
size: 759
size: 762
location: src/tests/client/test-client.py:test_003()/78
cmd: $NMCLI
lang: C
returncode: 0
stdout: 641 bytes
stdout: 644 bytes
>>>
eth1: connected to ethernet
"eth1"
@@ -3357,15 +3357,15 @@ eth0: connected to ethernet
"eth0"
ethernet (virtual), C0:61:AE:26:4D:D7, hw
wlan0: unavailable
wlan0: disconnected
"wlan0"
wifi (virtual), DC:39:87:BA:3E:5D, hw
wlan1: unavailable
wlan1: disconnected
"wlan1"
wifi (virtual), AC:4E:5B:7B:57:49, hw
wlan1: unavailable
wlan1: disconnected
"wlan1"
wifi (virtual), 24:C4:52:BC:3D:37, hw
@@ -3393,15 +3393,15 @@ eth0: połączono do ethernet
"eth0"
ethernet (virtual), C0:61:AE:26:4D:D7, sprzęt
wlan0: niedostępne
wlan0: rozłączono
"wlan0"
wifi (virtual), DC:39:87:BA:3E:5D, sprzęt
wlan1: niedostępne
wlan1: rozłączono
"wlan1"
wifi (virtual), AC:4E:5B:7B:57:49, sprzęt
wlan1: niedostępne
wlan1: rozłączono
"wlan1"
wifi (virtual), 24:C4:52:BC:3D:37, sprzęt

File diff suppressed because it is too large Load Diff

View File

@@ -2445,8 +2445,11 @@ class TestNmCloudSetup(unittest.TestCase):
return f
def _mock_devices(self):
# Add a device with an active connection that has IPv4 configured
self.ctx.srv.op_AddObj("WiredDevice", iface="eth0", mac="cc:00:00:00:00:01")
self.ctx.srv.op_AddObj("WiredDevice", iface="eth0", mac=self._mac1)
self.ctx.srv.op_AddObj("WiredDevice", iface="eth1", mac=self._mac2)
def _mock_connection1(self):
# Active connection that has IPv4 configured for device1
self.ctx.srv.addAndActivateConnection(
{
"connection": {"type": "802-3-ethernet", "id": "con-eth0"},
@@ -2456,8 +2459,8 @@ class TestNmCloudSetup(unittest.TestCase):
delay=0,
)
def _mock_connection2(self):
# The second connection has no IPv4
self.ctx.srv.op_AddObj("WiredDevice", iface="eth1", mac="cc:00:00:00:00:02")
self.ctx.srv.addAndActivateConnection(
{"connection": {"type": "802-3-ethernet", "id": "con-eth1"}},
"/org/freedesktop/NetworkManager/Devices/2",
@@ -2465,13 +2468,18 @@ class TestNmCloudSetup(unittest.TestCase):
delay=0,
)
def _mock_connections(self):
self._mock_devices()
self._mock_connection1()
self._mock_connection2()
def _mock_path(self, path, body):
self.md_conn.request("PUT", path, body=body)
self.md_conn.getresponse().read()
@cloud_setup_test
def test_aliyun(self):
self._mock_devices()
self._mock_connections()
_aliyun_meta = "/2016-01-01/meta-data/"
_aliyun_macs = _aliyun_meta + "network/interfaces/macs/"
@@ -2527,12 +2535,15 @@ class TestNmCloudSetup(unittest.TestCase):
)
pexp.expect("provider aliyun detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("get-config: start fetching meta data")
pexp.expect("get-config: success")
pexp.expect("meta data received")
# One of the devices has no IPv4 configuration to be modified
pexp.expect("device has no suitable applied connection. Skip")
pexp.expect("skip applied connection due to missing IPv4 configuration")
# The other one was lacking an address set it up.
pexp.expect("some changes were applied for provider aliyun")
(exitstatus, signalstatus, valgrind_log) = self.ctx.cmd_close_pexpect(pexp)
@@ -2555,7 +2566,10 @@ class TestNmCloudSetup(unittest.TestCase):
)
pexp.expect("provider aliyun detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("get-config: starting")
pexp.expect("get-config: success")
pexp.expect("meta data received")
@@ -2572,7 +2586,7 @@ class TestNmCloudSetup(unittest.TestCase):
@cloud_setup_test
def test_azure(self):
self._mock_devices()
self._mock_connections()
_azure_meta = "/metadata/instance"
_azure_iface = _azure_meta + "/network/interface/"
@@ -2616,7 +2630,10 @@ class TestNmCloudSetup(unittest.TestCase):
)
pexp.expect("provider azure detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("found azure interfaces: 2")
pexp.expect(r"interface\[0]: found a matching device with hwaddr")
pexp.expect(
@@ -2628,7 +2645,7 @@ class TestNmCloudSetup(unittest.TestCase):
pexp.expect("get-config: success")
pexp.expect("meta data received")
# One of the devices has no IPv4 configuration to be modified
pexp.expect("device has no suitable applied connection. Skip")
pexp.expect("skip applied connection due to missing IPv4 configuration")
# The other one was lacking an address set it up.
pexp.expect("some changes were applied for provider azure")
(exitstatus, signalstatus, valgrind_log) = self.ctx.cmd_close_pexpect(pexp)
@@ -2651,7 +2668,10 @@ class TestNmCloudSetup(unittest.TestCase):
)
pexp.expect("provider azure detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("get-config: starting")
pexp.expect("get-config: success")
pexp.expect("meta data received")
@@ -2668,7 +2688,7 @@ class TestNmCloudSetup(unittest.TestCase):
@cloud_setup_test
def test_ec2(self):
self._mock_devices()
self._mock_connections()
_ec2_macs = "/2018-09-24/meta-data/network/interfaces/macs/"
self._mock_path("/latest/meta-data/", "ami-id\n")
@@ -2702,12 +2722,15 @@ class TestNmCloudSetup(unittest.TestCase):
)
pexp.expect("provider ec2 detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("get-config: starting")
pexp.expect("get-config: success")
pexp.expect("meta data received")
# One of the devices has no IPv4 configuration to be modified
pexp.expect("device has no suitable applied connection. Skip")
pexp.expect("skip applied connection due to missing IPv4 configuration")
# The other one was lacking an address set it up.
pexp.expect("some changes were applied for provider ec2")
(exitstatus, signalstatus, valgrind_log) = self.ctx.cmd_close_pexpect(pexp)
@@ -2730,7 +2753,10 @@ class TestNmCloudSetup(unittest.TestCase):
)
pexp.expect("provider ec2 detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("get-config: starting")
pexp.expect("get-config: success")
pexp.expect("meta data received")
@@ -2747,7 +2773,7 @@ class TestNmCloudSetup(unittest.TestCase):
@cloud_setup_test
def test_gcp(self):
self._mock_devices()
self._mock_connections()
gcp_meta = "/computeMetadata/v1/instance/"
gcp_iface = gcp_meta + "network-interfaces/"
@@ -2772,13 +2798,16 @@ class TestNmCloudSetup(unittest.TestCase):
)
pexp.expect("provider GCP detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("found GCP interfaces: 2")
pexp.expect(r"GCP interface\[0]: found a requested device with hwaddr")
pexp.expect("get-config: success")
pexp.expect("meta data received")
# One of the devices has no IPv4 configuration to be modified
pexp.expect("device has no suitable applied connection. Skip")
pexp.expect("skip applied connection due to missing IPv4 configuration")
# The other one was lacking an address set it up.
pexp.expect("some changes were applied for provider GCP")
(exitstatus, signalstatus, valgrind_log) = self.ctx.cmd_close_pexpect(pexp)
@@ -2801,7 +2830,10 @@ class TestNmCloudSetup(unittest.TestCase):
)
pexp.expect("provider GCP detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("get-config: starting")
pexp.expect("get-config: success")
pexp.expect("meta data received")
@@ -2818,7 +2850,7 @@ class TestNmCloudSetup(unittest.TestCase):
@cloud_setup_test
def test_oci(self):
self._mock_devices()
self._mock_connections()
oci_meta = "/opc/v2/"
self._mock_path(oci_meta + "instance", "{}")
@@ -2864,12 +2896,15 @@ class TestNmCloudSetup(unittest.TestCase):
)
pexp.expect("provider oci detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("get-config: starting")
pexp.expect("get-config: success")
pexp.expect("meta data received")
# One of the devices has no IPv4 configuration to be modified
pexp.expect("device has no suitable applied connection. Skip")
pexp.expect("skip applied connection due to missing IPv4 configuration")
# The other one was lacking an address set it up.
pexp.expect("some changes were applied for provider oci")
(exitstatus, signalstatus, valgrind_log) = self.ctx.cmd_close_pexpect(pexp)
@@ -2892,7 +2927,10 @@ class TestNmCloudSetup(unittest.TestCase):
)
pexp.expect("provider oci detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("get-config: starting")
pexp.expect("get-config: success")
pexp.expect("meta data received")
@@ -2909,7 +2947,7 @@ class TestNmCloudSetup(unittest.TestCase):
@cloud_setup_test
def test_oci_vlans(self):
self._mock_devices()
self._mock_connections()
oci_meta = "/opc/v2/"
self._mock_path(oci_meta + "instance", "{}")
@@ -2966,17 +3004,23 @@ class TestNmCloudSetup(unittest.TestCase):
)
pexp.expect("provider oci detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("get-config: starting")
pexp.expect("get-config: success")
pexp.expect("meta data received")
# No configuration for the ethernets
pexp.expect('configuring "eth0"')
pexp.expect("device has no suitable applied connection. Skip")
pexp.expect("skip applied connection due to missing IPv4 configuration")
# Setting up the VLAN
pexp.expect("creating macvlan2 connection for VLAN 700 on CC:00:00:00:00:01...")
pexp.expect(
"creating macvlan2 connection for VLAN 700 on %s..."
% (TestNmCloudSetup._mac1.upper())
)
pexp.expect("creating vlan connection for VLAN 700 on C0:00:00:00:00:10...")
pexp.expect("some changes were applied for provider oci")
@@ -3008,12 +3052,15 @@ class TestNmCloudSetup(unittest.TestCase):
# Just the same ol' thing, just no changes this time
pexp.expect("provider oci detected")
pexp.expect("found interfaces: CC:00:00:00:00:01, CC:00:00:00:00:02")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("get-config: starting")
pexp.expect("get-config: success")
pexp.expect("meta data received")
pexp.expect('configuring "eth0"')
pexp.expect("device has no suitable applied connection. Skip")
pexp.expect("skip applied connection due to missing IPv4 configuration")
pexp.expect("no changes were applied for provider oci")
(exitstatus, signalstatus, valgrind_log) = self.ctx.cmd_close_pexpect(pexp)
@@ -3024,6 +3071,89 @@ class TestNmCloudSetup(unittest.TestCase):
)
self.assertEqual(exitstatus, 0, "Unexpectedly returned a non-zero status")
@cloud_setup_test
def test_oci_vm_vnic(self):
# One device unconnected, and one with a connection that needs changes
self._mock_devices()
self._mock_connection2()
oci_meta = "/opc/v2/"
self._mock_path(oci_meta + "instance", "{}")
self._mock_path(
oci_meta + "vnics",
"""
[
{
"macAddr": "%s",
"privateIp": "%s",
"subnetCidrBlock": "172.31.16.0/20",
"virtualRouterIp": "172.31.16.1",
"vlanTag": 1337,
"vnicId": "ocid1.vnic.oc1.cz-adamov1.foobarbaz"
},
{
"macAddr": "%s",
"privateIp": "%s",
"subnetCidrBlock": "172.31.166.0/20",
"virtualRouterIp": "172.31.166.1",
"vlanTag": 8086,
"vnicId": "ocid1.vnic.oc1.uk-hogwarts.expelliarmus"
}
]
"""
% (
TestNmCloudSetup._mac1,
TestNmCloudSetup._ip1,
TestNmCloudSetup._mac2,
TestNmCloudSetup._ip2,
),
)
pexp = self.ctx.cmd_call_pexpect(
ENV_NM_TEST_CLIENT_CLOUD_SETUP_PATH,
[],
{
"NM_CLOUD_SETUP_OCI_HOST": self.md_url,
"NM_CLOUD_SETUP_LOG": "trace",
"NM_CLOUD_SETUP_OCI": "yes",
},
)
pexp.expect("provider oci detected")
pexp.expect(
"found interfaces: %s, %s"
% (TestNmCloudSetup._mac1.upper(), TestNmCloudSetup._mac2.upper())
)
pexp.expect("get-config: starting")
pexp.expect("get-config: success")
pexp.expect("meta data received")
# First device lacks a connection: a new one will be created
pexp.expect('config device eth0: connection "connection-2"')
# Second device is skipped because it's activated without IPv4
pexp.expect(
"config device CC:00:00:00:00:02: skip applied connection due to missing IPv4 configuration"
)
# Finished!
pexp.expect("some changes were applied for provider oci")
(exitstatus, signalstatus, valgrind_log) = self.ctx.cmd_close_pexpect(pexp)
Util.valgrind_check_log(valgrind_log, "test_oci_vm_vnic")
self.assertIsNone(
signalstatus,
"Unexpectedly got " + Util.signal_no_to_str(signalstatus or 0),
)
self.assertEqual(exitstatus, 0, "Unexpectedly returned a non-zero status")
# TODO: Actually check the contents of the connection
# Probably needs changes to the mock service API
conn_macvlan = self.ctx.srv.findConnections(con_id="connection-3")
assert conn_macvlan is not None
conn_vlan = self.ctx.srv.findConnections(con_id="connection-4")
assert conn_vlan is not None
###############################################################################

View File

@@ -868,7 +868,7 @@ class Device(ExportedObj):
self.activation_state_change_delay_ms = 50
self.hwaddr = hwaddr is None if "" else hwaddr
self.prp_state = NM.DeviceState.UNAVAILABLE
self.prp_state = NM.DeviceState.DISCONNECTED
if devtype == NM.DeviceType.MODEM:
udi = "/org/freedesktop/ModemManager1/Modem/0"