aboutsummaryrefslogtreecommitdiff
path: root/test/shell/system_id.sh
blob: 5bb5c3a9e69ae56cec93349136ff194b3b42c854 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
#!/bin/sh
# Copyright (C) 2015 Red Hat, Inc. All rights reserved.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

test_description='Test system_id'

. lib/inittest

test -e LOCAL_LVMPOLLD && skip

aux prepare_devs 1

# with clvm enabled, vgcreate with no -c option creates a clustered vg,
# which should have no system id

if [ -e LOCAL_CLVMD ]; then
SID1=sidfoolocal
SID2=""
LVMLOCAL=etc/lvmlocal.conf
rm -f $LVMLOCAL
echo "local {" > $LVMLOCAL
echo "  system_id = $SID1" >> $LVMLOCAL
echo "}" >> $LVMLOCAL
aux lvmconf "global/system_id_source = lvmlocal"
vgcreate $vg1 "$dev1"
vgs -o+systemid $vg1
check vg_field $vg1 systemid $SID2
vgremove $vg1
rm -f $LVMLOCAL
exit 0
fi

# create vg with system_id using each source

## none

SID=""
aux lvmconf "global/system_id_source = none"
vgcreate $vg1 "$dev1"
check vg_field $vg1 systemid $SID
vgremove $vg1

# FIXME - print 'life' config data
eval $(lvmconfig global/etc 2>/dev/null || lvmconfig --type default global/etc)

## machineid
if [ -e $etc/machine-id ]; then
SID=$(cat $etc/machine-id)
aux lvmconf "global/system_id_source = machineid"
vgcreate $vg1 "$dev1"
vgs -o+systemid $vg1
check vg_field $vg1 systemid $SID
vgremove $vg1
fi

## uname

SID1=$(uname -n)
if [ -n $SID1 ]; then
aux lvmconf "global/system_id_source = uname"
SID2=$(lvm systemid | awk '{ print $3 }')
vgcreate $vg1 "$dev1"
vgs -o+systemid $vg1
check vg_field $vg1 systemid $SID2
vgremove $vg1
fi

## lvmlocal

SID=sidfoolocal
LVMLOCAL=etc/lvmlocal.conf
rm -f $LVMLOCAL
echo "local {" > $LVMLOCAL
echo "  system_id = $SID" >> $LVMLOCAL
echo "}" >> $LVMLOCAL
aux lvmconf "global/system_id_source = lvmlocal"
vgcreate $vg1 "$dev1"
vgs -o+systemid $vg1
check vg_field $vg1 systemid $SID
vgremove $vg1
rm -f $LVMLOCAL

## file

SID=sidfoofile
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
vgcreate $vg1 "$dev1"
vgs -o+systemid $vg1
check vg_field $vg1 systemid $SID
vgremove $vg1
rm -f $SIDFILE

# override system_id to create a foreign vg, then fail to use the vg

SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg, overriding the local system_id so the vg looks foreign
vgcreate --systemid $SID2 $vg1 "$dev1"
# normal vgs is not an error and does not see the vg
vgs >err
not grep $vg1 err
# vgs on the foreign vg is an error and not displayed
not vgs $vg1 >err
not grep $vg1 err
# fail to remove foreign vg
not vgremove $vg1
# using --foreign we can see foreign vg
vgs --foreign >err
grep $vg1 err
vgs --foreign $vg1 >err
grep $vg1 err
# change the local system_id to the second value, making the vg not foreign
echo "$SID2" > $SIDFILE
# we can now see and remove the vg
vgs $vg1 >err
grep $vg1 err
vgremove $vg1
rm -f $SIDFILE

# create a vg, then change the local system_id, making the vg foreign

SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs >err
grep $vg1 err
# change the local system_id, making the vg foreign
echo "$SID2" > $SIDFILE
# normal vgs doesn't see the vg
vgs >err
not grep $vg1 err
# using --foreign we can see the vg
vgs --foreign >err
grep $vg1 err
# change the local system_id back to the first value, making the vg not foreign
echo "$SID1" > $SIDFILE
vgs >err
grep $vg1 err
vgremove $vg1
rm -f $SIDFILE

# create a vg, then change the vg's system_id, making it foreign

SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs >err
grep $vg1 err
# change the vg's system_id, making the vg foreign
echo "y" | vgchange --systemid $SID2 $vg1
# normal vgs doesn't see the vg
vgs >err
not grep $vg1 err
# using --foreign we can see the vg
vgs --foreign >err
grep $vg1 err
# change the local system_id to the second system_id so we can remove the vg
echo "$SID2" > $SIDFILE
vgs >err
grep $vg1 err
vgremove $vg1
rm -f $SIDFILE

# create a vg, create active lvs in it, change our system_id, making
# the VG foreign, verify that we can still see the foreign VG,
# and can deactivate the LVs

SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
lvcreate -n $lv1 -l 2 $vg1
# normal vgs sees the vg and lv
vgs >err
grep $vg1 err
check lv_exists $vg1 $lv1
# change our system_id, making the vg foreign, but accessible
echo "$SID2" > $SIDFILE
vgs >err
grep $vg1 err
check lv_exists $vg1 $lv1
# can deactivate the lv
lvchange -an $vg1/$lv1
# now that the foreign vg has no active lvs, we can't access it
not lvremove $vg1/$lv1
not vgremove $vg1
# change our system_id back to match the vg so it's not foreign
echo "$SID1" > $SIDFILE
vgs >err
grep $vg1 err
lvremove $vg1/$lv1
vgremove $vg1
rm -f $SIDFILE

# local system has no system_id, so it can't access a vg with a system_id

SID1=sidfoofile1
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
aux lvmconf "global/system_id_source = none"
vgs >err
not grep $vg1 err
not vgs $vg1 >err
not grep $vg1 err
aux lvmconf "global/system_id_source = file"
vgs >err
grep $vg1 err
vgremove $vg1
rm -f $SIDFILE

# local system has a system_id, and can use a vg without a system_id

SID1=sidfoofile1
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
# create a vg with no system_id
aux lvmconf "global/system_id_source = none"
vgcreate $vg1 "$dev1"
check vg_field $vg1 systemid ""
# set a local system_id
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# check we can see and use the vg with no system_id
vgs >err
grep $vg1 err
vgs $vg1 >err
grep $vg1 err
vgremove $vg1
rm -f $SIDFILE

# vgexport clears system_id, vgimport sets system_id

SID1=sidfoofile1
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs -o+systemid >err
grep $vg1 err
grep $SID1 err
# after vgexport there is no systemid
vgexport $vg1
vgs -o+systemid >err
grep $vg1 err
not grep $SID1 err
# after vgimport there is a systemid
vgimport $vg1
vgs -o+systemid >err
grep $vg1 err
grep $SID1 err
vgremove $vg1
rm -f $SIDFILE

# vgchange -cy clears system_id, vgchange -cn sets system_id

SID1=sidfoofile1
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs -o+systemid >err
grep $vg1 err
grep $SID1 err
# after vgchange -cy there is no systemid
echo "y" | vgchange -cy $vg1
vgs --config 'global { locking_type=0 }' -o+systemid $vg1 >err
grep $vg1 err
not grep $SID1 err
# after vgchange -cn there is a systemid
vgchange --config 'global { locking_type=0 }' -cn $vg1
vgs -o+systemid >err
grep $vg1 err
grep $SID1 err
vgremove $vg1
rm -f $SIDFILE

# Test max system_id length (128) and invalid system_id characters.
# The 128 length limit is imposed before invalid characters are omitted.

SIDFILE=etc/lvm_test.conf

# 120 numbers followed by 8 letters (max len)
SID1=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789abcdefgh
# 120 numbers followed by 9 letters (too long by 1 character, the last is omitted)
SID2=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789abcdefghi

# max len system_id should appear normally
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs -o+systemid $vg1 >err
grep $vg1 err
grep $SID1 err
vgremove $vg1
rm -f $SIDFILE

# max+1 len system_id should be missing the last character
rm -f $SIDFILE
echo "$SID2" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs -o+systemid $vg1 >err
grep $vg1 err
grep $SID1 err
not grep $SID2 err
vgremove $vg1
rm -f $SIDFILE

# max len system_id containing an invalid character should appear without
# the invalid character
# 120 numbers followed by invalid '%' character followed by 8 letters (too long by 1 character)
SID1=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789%abcdefgh
# After the invalid character is omitted from SID1
# The string is truncated to max length (128) before the invalid character is omitted
SID2=012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789abcdefg
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs -o+systemid $vg1 >err
grep $vg1 err
not grep $SID1 err
grep $SID2 err
vgremove $vg1
rm -f $SIDFILE

# contains a bunch of invalid characters
SID1="?%$&A.@1]"
# SID1 without the invalid characters
SID2=A.1

rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs -o+systemid $vg1 >err
grep $vg1 err
not grep $SID1 err
grep $SID2 err
vgremove $vg1
rm -f $SIDFILE


# pvs: pv in a foreign vg not reported
# pvs --foreign: pv in a foreign vg is reported

SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal pvs sees the vg and pv
pvs >err
grep $vg1 err
grep "$dev1" err
# change the local system_id, making the vg foreign
echo "$SID2" > $SIDFILE
# normal pvs does not see the vg or pv
pvs >err
not grep $vg1 err
not grep "$dev1" err
# pvs --foreign does see the vg and pv
pvs --foreign >err
grep $vg1 err
grep "$dev1" err
# change the local system_id back so the vg can be removed
echo "$SID1" > $SIDFILE
vgremove $vg1
rm -f $SIDFILE

# lvs: lvs in a foreign vg not reported
# lvs --foreign: lvs in a foreign vg are reported

SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
lvcreate -n $lv1 -l 2 $vg1
lvchange -an $vg1/$lv1
# normal lvs sees the vg and lv
lvs >err
grep $vg1 err
grep $lv1 err
# change the local system_id, making the vg foreign
echo "$SID2" > $SIDFILE
# normal lvs does not see the vg or lv
lvs >err
not grep $vg1 err
not grep $lv1 err
# lvs --foreign does see the vg and lv
lvs --foreign >err
grep $vg1 err
grep $lv1 err
# change the local system_id back so the vg can be removed
echo "$SID1" > $SIDFILE
lvremove $vg1/$lv1
vgremove $vg1
rm -f $SIDFILE

# use extra_system_ids to read a foreign VG

SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
LVMLOCAL=etc/lvmlocal.conf
rm -f $LVMLOCAL
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs >err
grep $vg1 err
# change the local system_id, making the vg foreign
echo "$SID2" > $SIDFILE
# normal vgs doesn't see the vg
vgs >err
not grep $vg1 err
# using --foreign we can see the vg
vgs --foreign >err
grep $vg1 err
# add the first system_id to extra_system_ids so we can see the vg
echo "local {" > $LVMLOCAL
echo "  extra_system_ids = [ $SID1" ] >> $LVMLOCAL
echo "}" >> $LVMLOCAL
vgs >err
grep $vg1 err
vgremove $vg1
rm -f $SIDFILE
rm -f $LVMLOCAL

# vgcreate --systemid "" creates a vg without a system_id even if source is set
SID1=sidfoofile1
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate --systemid "" $vg1 "$dev1"
# normal vgs sees the vg
vgs >err
grep $vg1 err
# our system_id is not displayed for the vg
vgs -o+systemid >err
not grep $SID1 err
vgremove $vg1
rm -f $SIDFILE

# vgchange --systemid "" clears the system_id on owned vg
SID1=sidfoofile1
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs >err
grep $vg1 err
# the vg has our system_id
vgs -o+systemid >err
grep $SID1 err
# clear the system_id
vgchange --yes --systemid "" $vg1
# normal vgs sees the vg
vgs >err
grep $vg1 err
# the vg does not have our system_id
vgs -o+systemid >err
not grep $SID1 err
vgremove $vg1
rm -f $SIDFILE

# vgchange --systemid does not set the system_id on foreign vg
SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $LVMLOCAL
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs >err
grep $vg1 err
# change the local system_id, making the vg foreign
echo "$SID2" > $SIDFILE
# normal vgs doesn't see the vg
vgs >err
not grep $vg1 err
# using --foreign we can see the vg
vgs --foreign >err
grep $vg1 err
# cannot clear the system_id of the foreign vg
not vgchange --yes --systemid "" $vg1
# cannot set the system_id of the foreign vg
not vgchange --yes --systemid foo $vg1
# change our system_id back so we can remove the vg
echo "$SID1" > $SIDFILE
vgremove $vg1
rm -f $SIDFILE

# vgcfgbackup backs up foreign vg with --foreign
SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $LVMLOCAL
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg
vgcreate $vg1 "$dev1"
# normal vgs sees the vg
vgs >err
grep $vg1 err
# change the local system_id, making the vg foreign
echo "$SID2" > $SIDFILE
# normal vgs doesn't see the vg
vgs >err
not grep $vg1 err
# using --foreign we can back up the vg
not vgcfgbackup $vg1
vgcfgbackup --foreign $vg1
# change our system_id back so we can remove the vg
echo "$SID1" > $SIDFILE
vgremove $vg1
rm -f $SIDFILE



# Test handling of bad system_id source configurations
# The commands should proceed without a system_id.
# Look at the warning/error messages.

# vgcreate with source machineid, where no $etc/machine-id file exists
if [ ! -e $etc/machine-id ]; then
SID=""
aux lvmconf "global/system_id_source = machineid"
vgcreate $vg1 "$dev1" 2>&1 | tee err
vgs -o+systemid $vg1
check vg_field $vg1 systemid $SID
grep "No system ID found from system_id_source" err
vgremove $vg1
fi

# vgcreate with source uname, but uname is localhost
# TODO: don't want to change the hostname on the test machine...

# vgcreate with source lvmlocal, but no lvmlocal.conf file
SID=""
rm -f $LVMLOCAL
aux lvmconf "global/system_id_source = lvmlocal"
vgcreate $vg1 "$dev1" 2>&1 | tee err
vgs -o+systemid $vg1
check vg_field $vg1 systemid $SID
grep "No system ID found from system_id_source" err
vgremove $vg1
rm -f $LVMLOCAL

# vgcreate with source lvmlocal, but no system_id = "x" entry
SID=""
LVMLOCAL=etc/lvmlocal.conf
rm -f $LVMLOCAL
echo "local {" > $LVMLOCAL
# echo "  system_id = $SID" >> $LVMLOCAL
echo "}" >> $LVMLOCAL
aux lvmconf "global/system_id_source = lvmlocal"
vgcreate $vg1 "$dev1" 2>&1 | tee err
vgs -o+systemid $vg1
check vg_field $vg1 systemid $SID
grep "No system ID found from system_id_source" err
vgremove $vg1
rm -f $LVMLOCAL

# vgcreate with source lvmlocal, and empty string system_id = ""
SID=""
LVMLOCAL=etc/lvmlocal.conf
rm -f $LVMLOCAL
echo "local {" > $LVMLOCAL
echo "  system_id = \"\"" >> $LVMLOCAL
echo "}" >> $LVMLOCAL
aux lvmconf "global/system_id_source = lvmlocal"
vgcreate $vg1 "$dev1" 2>&1 | tee err
vgs -o+systemid $vg1
check vg_field $vg1 systemid $SID
grep "No system ID found from system_id_source" err
vgremove $vg1
rm -f $LVMLOCAL

# vgcreate with source file, but no system_id_file config
SID=""
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
aux lvmconf "global/system_id_source = file"
vgcreate $vg1 "$dev1" 2>&1 | tee err
vgs -o+systemid $vg1
check vg_field $vg1 systemid $SID
grep "No system ID found from system_id_source" err
vgremove $vg1
rm -f $SIDFILE

# vgcreate with source file, but system_id_file does not exist
SID=""
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
vgcreate $vg1 "$dev1" 2>&1 | tee err
vgs -o+systemid $vg1
check vg_field $vg1 systemid $SID
grep "No system ID found from system_id_source" err
vgremove $vg1
rm -f $SIDFILE


# Test cases where lvmetad cache of a foreign VG are out of date
# because the foreign owner has changed the VG.

test ! -e LOCAL_LVMETAD && exit 0

# When a foreign vg is newer on disk than in lvmetad, using --foreign
# should find the newer version.  This simulates a foreign host changing
# foreign vg by turning off lvmetad when we create an lv in the vg.
SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg with an lv
vgcreate $vg1 "$dev1"
lvcreate -n $lv1 -l 2 -an $vg1
# normal vgs sees the vg and lv
vgs >err
grep $vg1 err
check lv_exists $vg1 $lv1
# go around lvmetad to create another lv in the vg,
# forcing the lvmetad copy to be older than on disk.
aux lvmconf 'global/use_lvmetad = 0'
lvcreate -n $lv2 -l 2 -an $vg1
aux lvmconf 'global/use_lvmetad = 1'
# verify that the second lv is not in lvmetad
lvs $vg1 >err
grep $lv1 err
not grep $lv2 err
# change our system_id, making the vg foreign
echo "$SID2" > $SIDFILE
vgs >err
not grep $vg1 err
# using --foreign, we will get the latest vg from disk
lvs --foreign $vg1 >err
grep $vg1 err
grep $lv1 err
grep $lv2 err
# change our system_id back to match the vg so it's not foreign
echo "$SID1" > $SIDFILE
lvremove $vg1/$lv1
lvremove $vg1/$lv2
vgremove $vg1
rm -f $SIDFILE

# vgimport should find the exported vg on disk even though
# lvmetad's copy of the vg shows it's foreign.
SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg with an lv
vgcreate $vg1 "$dev1"
lvcreate -n $lv1 -l 2 -an $vg1
# normal vgs sees the vg and lv
vgs >err
grep $vg1 err
check lv_exists $vg1 $lv1
# go around lvmetad to export the vg so that lvmetad still
# has the original vg owned by SID1 in its cache
aux lvmconf 'global/use_lvmetad = 0'
vgexport $vg1
aux lvmconf 'global/use_lvmetad = 1'
# change the local system_id so the lvmetad copy of the vg is foreign
echo "$SID2" > $SIDFILE
# verify that lvmetad thinks the vg is foreign
# (don't use --foreign to verify this because that will cause
# the lvmetad cache to be updated, which we don't want yet)
not vgs $vg1
# attempt to import the vg that has been exported, but
# which lvmetad thinks is foreign
vgimport $vg1
# verify that the imported vg has our system_id
vgs -o+systemid $vg1 >err
grep $vg1 err
grep $SID2 err
check lv_exists $vg1 $lv1
lvremove $vg1/$lv1
vgremove $vg1
rm -f $SIDFILE

# pvscan --cache should cause the latest version of a foreign VG to be
# cached in lvmetad.  Without the --cache option, pvscan will see the old
# version of the VG.
SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg with an lv
vgcreate $vg1 "$dev1"
lvcreate -n $lv1 -l 2 -an $vg1
# normal vgs sees the vg and lv
vgs >err
grep $vg1 err
check lv_exists $vg1 $lv1
# go around lvmetad to create another lv in the vg,
# forcing the lvmetad copy to be older than on disk.
aux lvmconf 'global/use_lvmetad = 0'
lvcreate -n $lv2 -l 2 -an $vg1
aux lvmconf 'global/use_lvmetad = 1'
# verify that the second lv is not in lvmetad
lvs $vg1 >err
grep $lv1 err
not grep $lv2 err
# verify that after pvscan without --cache, lvmetad still
# reports the old version
pvscan
lvs $vg1 >err
grep $lv1 err
not grep $lv2 err
# change our system_id, making the vg foreign
echo "$SID2" > $SIDFILE
not vgs $vg1 >err
not grep $vg1 err
# use pvscan --cache to update the foreign vg in lvmetad
pvscan --cache
not vgs $vg1 >err
not grep $vg1 err
# change our system_id back to SID1 so we can check that
# lvmetad has the latest copy of the vg (without having
# to use --foreign to check)
echo "$SID1" > $SIDFILE
vgs $vg1 >err
grep $vg1 err
lvs $vg1 >err
grep $lv1 err
grep $lv2 err
lvremove $vg1/$lv1
lvremove $vg1/$lv2
vgremove $vg1
rm -f $SIDFILE

# repeat the same test for vgscan instead of pvscan
SID1=sidfoofile1
SID2=sidfoofile2
SIDFILE=etc/lvm_test.conf
rm -f $SIDFILE
echo "$SID1" > $SIDFILE
aux lvmconf "global/system_id_source = file" \
	    "global/system_id_file = \"$SIDFILE\""
# create a vg with an lv
vgcreate $vg1 "$dev1"
lvcreate -n $lv1 -l 2 -an $vg1
# normal vgs sees the vg and lv
vgs >err
grep $vg1 err
check lv_exists $vg1 $lv1
# go around lvmetad to create another lv in the vg,
# forcing the lvmetad copy to be older than on disk.
aux lvmconf 'global/use_lvmetad = 0'
lvcreate -n $lv2 -l 2 -an $vg1
aux lvmconf 'global/use_lvmetad = 1'
# verify that the second lv is not in lvmetad
lvs $vg1 >err
grep $lv1 err
not grep $lv2 err
# verify that after vgscan without --cache, lvmetad still
# reports the old version
vgscan
lvs $vg1 >err
grep $lv1 err
not grep $lv2 err
# change our system_id, making the vg foreign
echo "$SID2" > $SIDFILE
not vgs $vg1 >err
not grep $vg1 err
# use vgscan --cache to update the foreign vg in lvmetad
vgscan --cache
not vgs $vg1 >err
not grep $vg1 err
# change our system_id back to SID1 so we can check that
# lvmetad has the latest copy of the vg (without having
# to use --foreign to check)
echo "$SID1" > $SIDFILE
vgs $vg1 >err
grep $vg1 err
lvs $vg1 >err
grep $lv1 err
grep $lv2 err
lvremove $vg1/$lv1
lvremove $vg1/$lv2
vgremove $vg1
rm -f $SIDFILE