@@ -54,6 +54,85 @@ def test_010_os_metadata(self):
54
54
self .assertEqual (tpl .features .get ("os-distribution" ), "kali" )
55
55
self .assertEqual (tpl .features .get ("os-distribution-like" ), "debian" )
56
56
57
+ def test_020_custom_persist (self ):
58
+ self .testvm = self .app .add_new_vm (
59
+ "AppVM" ,
60
+ label = "red" ,
61
+ name = self .make_vm_name ("vm" ),
62
+ )
63
+ self .loop .run_until_complete (self .testvm .create_on_disk ())
64
+ self .testvm .features ["service.custom-persist" ] = "1"
65
+ self .testvm .features ["custom-persist.downloads" ] = (
66
+ "dir:user:user:0755:/home/user/Downloads"
67
+ )
68
+ self .testvm .features ["custom-persist.local_lib" ] = "/usr/local/lib"
69
+ self .testvm .features ["custom-persist.new_dir" ] = (
70
+ "dir:user:user:0755:/home/user/new_dir"
71
+ )
72
+ self .testvm .features ["custom-persist.new_file" ] = (
73
+ "file:user:user:0644:/home/user/new_file"
74
+ )
75
+ self .app .save ()
76
+
77
+ # start first time,
78
+ self .loop .run_until_complete (self .testvm .start ())
79
+ # do some changes
80
+ try :
81
+ self .loop .run_until_complete (
82
+ self .testvm .run_for_stdio (
83
+ "ls -ld /home/user/Downloads &&"
84
+ "test $(stat -c %U /home/user/Downloads) = user &&"
85
+ "test $(stat -c %G /home/user/Downloads) = user &&"
86
+ "test $(stat -c %a /home/user/Downloads) = 755 &&"
87
+ "echo test1 > /home/user/Downloads/download.txt &&"
88
+ "ls -ld /home/user/new_dir &&"
89
+ "test $(stat -c %U /home/user/new_dir) = user &&"
90
+ "test $(stat -c %G /home/user/new_dir) = user &&"
91
+ "test $(stat -c %a /home/user/new_dir) = 755 &&"
92
+ "echo test2 > /home/user/new_dir/file_in_new_dir.txt &&"
93
+ "mkdir -p /home/user/Documents &&"
94
+ "chown user /home/user/Documents &&"
95
+ "echo test3 > /home/user/Documents/doc.txt &&"
96
+ "echo TEST4=test4 >> /home/user/.bashrc &&"
97
+ "test $(stat -c %U /home/user/new_file) = user &&"
98
+ "test $(stat -c %G /home/user/new_file) = user &&"
99
+ "test $(stat -c %a /home/user/new_file) = 644 &&"
100
+ "echo test5 > /home/user/new_file &&"
101
+ "mkdir -p /usr/local/bin &&"
102
+ "ln -s /bin/true /usr/local/bin/true-copy &&"
103
+ "mkdir -p /usr/local/lib/subdir &&"
104
+ "echo touch /etc/test5.flag >> /rw/config/rc.local" ,
105
+ user = "root" ,
106
+ )
107
+ )
108
+ except subprocess .CalledProcessError as e :
109
+ self .fail (
110
+ f"Calling '{ e .cmd } ' failed with { e .returncode } : "
111
+ f"{ e .stdout } { e .stderr } "
112
+ )
113
+ self .loop .run_until_complete (self .testvm .shutdown (wait = True ))
114
+ # and then start again to compare what survived
115
+ self .loop .run_until_complete (self .testvm .start ())
116
+ try :
117
+ self .loop .run_until_complete (
118
+ self .testvm .run_for_stdio (
119
+ "grep test1 /home/user/Downloads/download.txt &&"
120
+ "grep test2 /home/user/new_dir/file_in_new_dir.txt &&"
121
+ "! ls -dl /home/user/Documents/doc.txt &&"
122
+ "! grep TEST4=test4 /home/user/.bashrc &&"
123
+ "grep test5 /home/user/new_file &&"
124
+ "! ls -l /usr/local/bin/true-copy &&"
125
+ "ls -dl /usr/local/lib/subdir &&"
126
+ "! ls -dl /etc/test5.flag" ,
127
+ user = "root" ,
128
+ )
129
+ )
130
+ except subprocess .CalledProcessError as e :
131
+ self .fail (
132
+ f"Too much / too little files persisted: { e .stdout } "
133
+ f"{ e .stderr } "
134
+ )
135
+
57
136
@unittest .skipUnless (
58
137
spawn .find_executable ("xdotool" ), "xdotool not installed"
59
138
)
0 commit comments