-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
404 lines (271 loc) · 15.5 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en" itemscope itemtype="http://schema.org/WebPage">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<title>openQA bites - openQA bites</title>
<meta name="author" content="phoenix"/><script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": "openQA bites",
"url": "https:\/\/openQA-Bites.github.io\/"
}
</script><script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"name": "",
"url": "https:\/\/openQA-Bites.github.io\/"
}
</script>
<meta property="og:title" content="openQA bites" />
<meta property="og:image" content="https://openQA-Bites.github.io/img/avatar-icon.png" />
<meta property="og:url" content="https://openQA-Bites.github.io/" />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="openQA bites" />
<meta name="twitter:title" content="openQA bites" />
<meta name="twitter:image" content="https://openQA-Bites.github.io/img/avatar-icon.png" />
<meta name="twitter:card" content="summary" />
<link href='https://openQA-Bites.github.io/img/favicon.ico' rel='icon' type='image/x-icon'/>
<meta name="generator" content="Hugo 0.80.0" />
<link rel="alternate" href="https://openQA-Bites.github.io/index.xml" type="application/rss+xml" title="openQA bites"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.css" integrity="sha384-9eLZqc9ds8eNjO3TmqPeYcDj8n+Qfa4nuSiGYa6DjLNcv9BtN69ZIulL9+8CqC9Y" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"><link rel="stylesheet" href="https://openQA-Bites.github.io/css/main.css" /><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800" /><link rel="stylesheet" href="https://openQA-Bites.github.io/css/syntax.css" /><link rel="stylesheet" href="https://openQA-Bites.github.io/css/codeblock.css" /><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.2/photoswipe.min.css" integrity="sha384-h/L2W9KefUClHWaty3SLE5F/qvc4djlyR4qY3NUV5HGQBBW7stbcfff1+I/vmsHh" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.2/default-skin/default-skin.min.css" integrity="sha384-iD0dNku6PYSIQLyfTOpB06F2KCZJAKLOThS5HRe8b3ibhdEQ6eKsFf/EeFxdOt5R" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top navbar-custom">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#main-navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="https://openQA-Bites.github.io/">openQA bites</a>
</div>
<div class="collapse navbar-collapse" id="main-navbar">
<ul class="nav navbar-nav navbar-right">
</ul>
</div>
<div class="avatar-container">
<div class="avatar-img-border">
<a title="openQA bites" href="https://openQA-Bites.github.io/">
<img class="avatar-img" src="https://openQA-Bites.github.io/img/avatar-icon.png" alt="openQA bites" />
</a>
</div>
</div>
</div>
</nav>
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
<div class="pswp__bg"></div>
<div class="pswp__scroll-wrap">
<div class="pswp__container">
<div class="pswp__item"></div>
<div class="pswp__item"></div>
<div class="pswp__item"></div>
</div>
<div class="pswp__ui pswp__ui--hidden">
<div class="pswp__top-bar">
<div class="pswp__counter"></div>
<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
<button class="pswp__button pswp__button--share" title="Share"></button>
<button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
<button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
<div class="pswp__preloader">
<div class="pswp__preloader__icn">
<div class="pswp__preloader__cut">
<div class="pswp__preloader__donut"></div>
</div>
</div>
</div>
</div>
<div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
<div class="pswp__share-tooltip"></div>
</div>
<button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
</button>
<button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
</button>
<div class="pswp__caption">
<div class="pswp__caption__center"></div>
</div>
</div>
</div>
</div>
<header class="header-section ">
<div class="intro-header no-img">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="page-heading">
<h1>openQA bites</h1>
<hr class="small">
<span class="page-subheading">Stories and tutorials from a humble openQA dev</span>
</div>
</div>
</div>
</div>
</div>
</header>
<div role="main" class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="posts-list">
<article class="post-preview">
<a href="https://openQA-Bites.github.io/posts/2021-02-04-background-scripts/">
<h2 class="post-title">Background bash commands</h2>
</a>
<p class="post-meta">
<span class="post-meta">
<i class="fas fa-calendar"></i> Posted on February 4, 2021
| <i class="fas fa-clock"></i> 3 minutes
| <i class="fas fa-book"></i> 534 words
| <i class="fas fa-user"></i> phoenix
</span>
</p>
<div class="post-entry">
<p>Most of the openQA test cases run command sequentially. One command nicely after the next one. But in some cases it can be useful, to run a handful of commands in parallel and then wait for them to finish. Here we are covering the caveats of using the bash background operator <code>&</code> in openQA.</p>
<p>The TL;DR is at the end of the post</p>
<h1 id="usage-example">Usage example</h1>
<p>For instance, in virtualization testing, we install a handful of virtual machines in parallel via ``virt-install`:</p>
<pre><code>assert_script_run('( virt-install --os-variant sles12sp3 --name sles12sp3 ... >> ~/virt-install_sles12sp3.txt 2>&1 &)');
assert_script_run('( virt-install --os-variant sles12sp4 --name sles12sp4 ... >> ~/virt-install_sles12sp4.txt 2>&1 &)');
assert_script_run('( virt-install --os-variant sles12sp5 --name sles12sp5 ... >> ~/virt-install_sles12sp5.txt 2>&1 &)');
</code></pre>
<p>The general problem is, that you would like to run a set of bash commands in parallel, and wait for all of them to complete. In terms of code, you would like to do the following:</p>
<pre><code>$ sleep 30 & # or another command that takes some time
$ sleep 30 &
$ sleep 30 &
$ sleep 30 &
$ sleep 30 &
$ wait
</code></pre>
<p>Unfortunately enclosing those comments by a simple <code>assert_script_run</code> will not work, because of the handling with the serial terminal.</p>
<pre><code>assert_script_run('sleep 30 &'); # will result in a bash syntax error
</code></pre>
<p>The problem is, that openqa adds something like <code>; echo ~59bn-\$?-"</code> at the end of the command, resulting in</p>
<pre><code>sleep 30 & ; echo ~59bn-\$?-
</code></pre>
<p>Now, <code>&</code> and <code>;</code> are both terminators in bash resulting in an empty command between those two’s which is not allowed. A quick fix is to add <code>true</code> in between those twos:</p>
<pre><code>assert_script_run('sleep 30 & true'); # OK!
</code></pre>
<h1 id="enclosing-within-brackets-is-a-bad-idea">Enclosing within brackets is a bad idea</h1>
<p>Another often seen solution is to enclose the commands between brackets:</p>
<pre><code>assert_script_run('(sleep 30 & )'); # don't do that!
</code></pre>
<p>This is fine, unless you need to interact with your background jobs. The reason is, that the commands between the brackets are not available in the outside context. This means, bash does not keep track of those processes, so that a subsequent <code>wait</code> will not wait for those. This can be seen in the following example</p>
<pre><code>$ (sleep 30 & ); wait # will not wait for sleep, terminates immediately
$ (sleep 30 & ); jobs # sleep is not visible
</code></pre>
<p>You can see, that the <code>sleep</code> command is not accessible in the context outside of the brackets. <code>wait</code> terminates immediately and <code>sleep</code> does not appear as a job in <code>jobs</code>. The correct way would be to omit the brackets and the semicolon:</p>
<pre><code>$ sleep 30 & wait
[1] 12015
$ sleep 30 & jobs
[1] 12038
[1]+ Running sleep 30 &
</code></pre>
<p>So, back to our starting point, if you enclose the commands in brackets, a subsequent <code>wait</code> will not work and this is why I believe that enclosing bash commands between brackets is a bad idea:</p>
<pre><code>assert_script_run('(sleep 30 & )');
assert_script_run('wait'); # Will NOT wait for the sleep above!
</code></pre>
<p>The correct solution would be to add a <code>true</code> at the end of the <code>sleep</code> command</p>
<pre><code>assert_script_run('sleep 30 & true');
assert_script_run('wait'); # this works
</code></pre>
<h1 id="tldr">TL;DR</h1>
<p>The correct way of running bash commands in the background is</p>
<pre><code>assert_script_run('sleep 30 & true');
assert_script_run('sleep 30 & true');
assert_script_run('wait');
</code></pre>
</div>
<div class="blog-tags">
<a href="https://openQA-Bites.github.io//tags/scripting/">Scripting</a>
</div>
</article>
</div>
</div>
</div>
</div>
<div class="page-meta">
</div>
<footer>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<ul class="list-inline text-center footer-links">
<li>
<a href="mailto:[email protected]" title="Email me">
<span class="fa-stack fa-lg">
<i class="fas fa-circle fa-stack-2x"></i>
<i class="fas fa-envelope fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://github.com/grisu48" title="GitHub">
<span class="fa-stack fa-lg">
<i class="fas fa-circle fa-stack-2x"></i>
<i class="fab fa-github fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://reddit.com/u/grisu48" title="Reddit">
<span class="fa-stack fa-lg">
<i class="fas fa-circle fa-stack-2x"></i>
<i class="fab fa-reddit-alien fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://linkedin.com/in/felix-niederwanger" title="LinkedIn">
<span class="fa-stack fa-lg">
<i class="fas fa-circle fa-stack-2x"></i>
<i class="fab fa-linkedin fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://https://chaos.social/@phoenix" title="Mastodon">
<span class="fa-stack fa-lg">
<i class="fas fa-circle fa-stack-2x"></i>
<i class="fab fa-mastodon fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://openQA-Bites.github.io/index.xml" title="RSS">
<span class="fa-stack fa-lg">
<i class="fas fa-circle fa-stack-2x"></i>
<i class="fas fa-rss fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
</ul>
<p class="credits copyright text-muted">
phoenix
• ©
2021
•
<a href="https://openQA-Bites.github.io/">openQA bites</a>
</p>
<p class="credits theme-by text-muted">
<a href="https://gohugo.io">Hugo v0.80.0</a> powered • Theme <a href="https://github.com/halogenica/beautifulhugo">Beautiful Hugo</a> adapted from <a href="https://deanattali.com/beautiful-jekyll/">Beautiful Jekyll</a>
</p>
</div>
</div>
</div>
</footer><script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/katex.min.js" integrity="sha384-K3vbOmF2BtaVai+Qk37uypf7VrgBubhQreNQe9aGsz9lB63dIFiQVlJbr92dw2Lx" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.10.0/contrib/auto-render.min.js" integrity="sha384-kmZOZB5ObwgQnS/DuDg6TScgOiWWBiVt0plIRkZCmE6rDZGrEOQeHM5PcHi+nyqe" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<script src="https://openQA-Bites.github.io/js/main.js"></script><script> renderMathInElement(document.body); </script><script src="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.2/photoswipe.min.js" integrity="sha384-QELNnmcmU8IR9ZAykt67vGr9/rZJdHbiWi64V88fCPaOohUlHCqUD/unNN0BXSqy" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/photoswipe/4.1.2/photoswipe-ui-default.min.js" integrity="sha384-m67o7SkQ1ALzKZIFh4CiTA8tmadaujiTa9Vu+nqPSwDOqHrDmxLezTdFln8077+q" crossorigin="anonymous"></script><script src="https://openQA-Bites.github.io/js/load-photoswipe.js"></script>
</body>
</html>