Skip to content

Commit 89bc739

Browse files
committed
feat: add ssh access to test VMs and add test with dynamic cinder volume attachment
Signed-off-by: Paul Kroeher <paul.kroeher@cyberus-technology.de> On-behalf-of: SAP paul.kroeher@sap.com
1 parent f24082d commit 89bc739

4 files changed

Lines changed: 121 additions & 17 deletions

File tree

modules/storage/cinder-storage-node.nix

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@
99
}:
1010
with lib;
1111
let
12-
# adminEnv = {
13-
# OS_USERNAME = "admin";
14-
# OS_PASSWORD = "admin";
15-
# OS_PROJECT_NAME = "admin";
16-
# OS_USER_DOMAIN_NAME = "Default";
17-
# OS_PROJECT_DOMAIN_NAME = "Default";
18-
# OS_AUTH_URL = "http://controller:5000/v3";
19-
# OS_IDENTITY_API_VERSION = "3";
20-
# };
2112
cfg = config.cinder-storage-node;
2213

2314
cinder_env = pkgs.python3.buildEnv.override {
@@ -32,6 +23,7 @@ let
3223
paths = [
3324
cinder_env
3425
pkgs.qemu
26+
pkgs.tgt
3527
];
3628
};
3729

@@ -52,6 +44,10 @@ let
5244
rootwrap_config = ${rootwrapConf}
5345
glance_api_servers = http://controller:9292
5446
verify_glance_signatures = disabled
47+
log_dir = /var/log/cinder
48+
iscsi_ip_address = $my_ip
49+
iscsi_port = 3260
50+
iscsi_target_prefix = iqn.2010-10.org.openstack:
5551
5652
[database]
5753
connection = mysql+pymysql://cinder:cinder@controller/cinder
@@ -77,6 +73,9 @@ let
7773
lvm_type = default
7874
target_protocol = iscsi
7975
target_helper = tgtadm
76+
iscsi_ip_address = $my_ip
77+
iscsi_port = 3260
78+
iscsi_target_prefix = iqn.2010-10.org.openstack:
8079
'';
8180

8281
cinderTgtConf = pkgs.writeText "cinder.conf" ''
@@ -169,7 +168,7 @@ in
169168
enable = true;
170169
description = "iSCSI target framework daemon";
171170
wantedBy = [ "multi-user.target" ];
172-
after = [
171+
after = [
173172
"network.target"
174173
"cinder-volume-group-setup.service"
175174
];
@@ -179,7 +178,7 @@ in
179178
];
180179
environment.TGTD_CONFIG = "/etc/tgt/targets.conf";
181180
serviceConfig = {
182-
ExecStart = "${pkgs.tgt}/bin/tgtd";
181+
ExecStart = "${pkgs.tgt}/bin/tgtd -f";
183182
ExecStartPost = [
184183
"${pkgs.coreutils}/bin/sleep 5"
185184
"${pkgs.tgt}/bin/tgtadm --op update --mode sys --name State -v offline"

modules/testing/README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SSH Access
2+
3+
## Storage VM
4+
5+
```bash
6+
ssh root@localhost -p 2022 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
7+
```
8+
9+
## Controller VM
10+
11+
```bash
12+
ssh root@localhost -p 1122 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
13+
```
14+
15+
# Cinder & tgtd
16+
17+
## Create volume
18+
19+
* login in to `controllerVM` or `storageVM`
20+
21+
```bash
22+
openstack volume create --size 4 TEST_VOL
23+
```
24+
25+
* Cinder will create a LVM logical volume in the volume group `cinder-volumes`.
26+
* At this time this volume will not be exposed as an iSCSI volume. This only happens when the volume is assigned to a VM.
27+
28+
## Assign volume to a VM
29+
30+
* create a new VM with: `openstack server create`
31+
* or look into system unit: `openstack-create-vm` on VM `controllerVM`
32+
33+
* attach volume to vm
34+
35+
```bash
36+
openstack server list
37+
openstack volume list
38+
openstack server add volume <INSTANCE_NAME_OR_ID> <VOLUME_NAME_OR_ID>
39+
```
40+
41+
* Verify tgtd status on `storageVM`: `tgt-admin --dump`
42+
* Cinder should generated a tgtd configuration file within: `/var/lib/cinder/volumes`
43+
* In the VM `computeVM` should appear a new block device `sda`. (`dmesg`)
44+
45+
```bash
46+
[root@storageVM:/var/lib/cinder/volumes]# l
47+
total 12K
48+
drwxr-xr-x 2 cinder cinder 4.0K Feb 24 08:16 .
49+
drwxr-xr-x 6 cinder cinder 4.0K Feb 24 08:09 ..
50+
-rw------- 1 cinder cinder 268 Feb 24 08:16 volume-64159e0c-18bb-449f-b1e0-86f198b170e4
51+
```

modules/testing/default.nix

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,26 @@ let
3333

3434
environment.systemPackages = [
3535
pkgs.openstackclient
36+
pkgs.openiscsi
37+
pkgs.sshpass
3638
];
3739

3840
environment.variables = adminEnv;
41+
42+
# enable easy access to test VMs with ssh
43+
users.users.root.openssh.authorizedKeys.keys = [
44+
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEMjGRp1/vaTxGiGbZnaSv4wu4LUUP7lGSGDFKfF31xw paul.kroeher@cyberus-technology.de"
45+
];
46+
47+
services.openssh = {
48+
enable = true;
49+
ports = [ 22 ];
50+
settings = {
51+
PasswordAuthentication = true;
52+
PermitRootLogin = "without-password"; # "yes", "without-password", "prohibit-password", "forced-commands-only", "no"
53+
};
54+
};
55+
3956
};
4057
};
4158
in
@@ -66,6 +83,10 @@ in
6683
vlan = 2;
6784
};
6885
};
86+
# enable ssh access
87+
forwardPorts = [
88+
{ from = "host"; host.port = 1122; guest.port = 22; }
89+
];
6990
};
7091

7192
systemd.services.openstack-create-vm = {
@@ -121,14 +142,13 @@ in
121142
matchConfig.Name = [ "eth0" ];
122143
networkConfig = {
123144
DHCP = "yes";
145+
DNS = "8.8.8.8";
124146
};
125147
};
126148
eth1 = {
127149
matchConfig.Name = [ "eth1" ];
128150
networkConfig = {
129151
Address = "10.0.0.11/24";
130-
Gateway = "10.0.0.1";
131-
DNS = "8.8.8.8";
132152
};
133153
};
134154

@@ -201,7 +221,7 @@ in
201221
diskSize = 4096;
202222
# add separate disk as LVM backend
203223
emptyDiskImages = [
204-
16384
224+
16384 # 16GB
205225
];
206226
interfaces = {
207227
eth1 = {
@@ -211,19 +231,31 @@ in
211231
vlan = 2;
212232
};
213233
};
234+
# enable ssh access
235+
forwardPorts = [
236+
{ from = "host"; host.port = 2022; guest.port = 22; }
237+
];
214238
};
215239

216240
systemd.network = {
217241
enable = true;
218242
wait-online.enable = false;
219243

220244
networks = {
245+
eth0 = {
246+
matchConfig.Name = [ "eth0" ];
247+
networkConfig = {
248+
DHCP = "yes";
249+
LinkLocalAddressing = "yes";
250+
KeepConfiguration = "yes";
251+
DNS = "8.8.8.8";
252+
};
253+
};
254+
221255
eth1 = {
222256
matchConfig.Name = [ "eth1" ];
223257
networkConfig = {
224258
Address = "10.0.0.20/24";
225-
Gateway = "10.0.0.1";
226-
DNS = "8.8.8.8";
227259
};
228260
};
229261

tests/openstack-default-setup.nix

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ pkgs.nixosTest {
6464
if status != 0:
6565
continue
6666
compute_nodes = json.loads(out)
67-
if len(net_agents) == 4 and len(compute_nodes) == 1 and compute_nodes[0].get("Host","None") == "computeVM":
67+
status, out = controllerVM.execute("openstack volume service list -f json")
68+
if status != 0:
69+
continue
70+
storage_nodes = json.loads(out)
71+
if len(storage_nodes) == 2 and len(net_agents) == 4 and len(compute_nodes) == 1 and compute_nodes[0].get("Host","None") == "computeVM":
6872
return True
6973
return False
7074
@@ -107,6 +111,10 @@ pkgs.nixosTest {
107111
controllerVM.wait_for_unit("nova-scheduler.service")
108112
controllerVM.wait_for_unit("nova-conductor.service")
109113
114+
# check all services on storageVM
115+
storageVM.wait_for_unit("tgtd.service")
116+
storageVM.wait_for_unit("cinder-volume.service")
117+
110118
assert wait_for_openstack()
111119
112120
controllerVM.succeed("systemctl start nova-host-discovery.service")
@@ -126,5 +134,19 @@ pkgs.nixosTest {
126134
# Ping the OpenStack VM from the controller host. We use the network
127135
# namespace dedicated for the VM to ping it.
128136
assert retry_until_succeed(controllerVM, f"ip netns exec {net_ns} ping -c 1 {vm_ip}", 30)
137+
138+
# create volume with 4GB
139+
controllerVM.execute("openstack volume create --size 4 test_vol")
140+
# attach volume to VM
141+
controllerVM.execute("openstack server add volume test_vm test_vol")
142+
# wait until volume is attached
143+
time.sleep(20)
144+
145+
retry_until_succeed(controllerVM, f"ip netns exec {net_ns} sshpass -p gocubsgo ssh cirros@{vm_ip} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null lsblk", 60)
146+
# check second block device of VM
147+
status, output = controllerVM.execute(f"ip netns exec {net_ns} sshpass -p gocubsgo ssh cirros@{vm_ip} -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null lsblk | grep vdb")
148+
output = output.strip()
149+
assert status == 0
150+
assert output == "vdb 252:16 0 4G 0 disk"
129151
'';
130152
}

0 commit comments

Comments
 (0)