I am currently running into the following error:
Error: Could not parse for environment production: Syntax error at end of file on node master.domain.org
while trying to run the below puppet code
puppet apply --parser future -e '$vars={
0 => '192.1.1.140',
1 => '192.1.1.141',
2 => '192.1.1.142',
} each($vars) |$id,$gate| { notice "${id} -> ${gate}" }'
Strangely though I can run this without issues,
puppet apply --parser future -e '$vars={
0 => '1.0',
1 => '1.1',
2 => '1.2',
} each($vars) |$id,$gate| { notice "${id} -> ${gate}" }'
Notice: Scope(Class[main]): 0 -> 1.0
Notice: Scope(Class[main]): 1 -> 1.1
Notice: Scope(Class[main]): 2 -> 1.2
Notice: Compiled catalog for master.domain.org in environment production in 0.33 seconds
Notice: Finished catalog run in 0.01 seconds
I assume it is something with the second(and third) dot, How can I fix this?
EDIT
I was doing some more testing and noticed this little gem
puppet apply --parser future -e '$ip='1.1-1' $vars={
0 => "${ip}.0",
1 => "${ip}.1",
2 => "${ip}.2",
} each($vars) |$id,$gate| { notice "${id} -> ${gate}" }'
Notice: Scope(Class[main]): 0 -> 0.10000000000000009.0
Notice: Scope(Class[main]): 1 -> 0.10000000000000009.1
Notice: Scope(Class[main]): 2 -> 0.10000000000000009.2
Notice: Compiled catalog for master.domain.org in environment production in 0.34 seconds
Notice: Finished catalog run in 0.02 seconds
Looks like its doing some weird mathematical expansion/interpretation?
Seems in this case, you need use double quote.
puppet apply --parser future -e '$vars={
0 => "192.1.1.140",
1 => "192.1.1.141",
2 => "192.1.1.142",
} each($vars) |$id,$gate| { notice "${id} -> ${gate}" }'
Related
I have been using jest lately to train my unit-test skills. On this process, I was able to reproduce their examples on website https://jestjs.io/docs/expect. Among others, the particular use case expect.objectContaining is somewhat troublesome. The given example uses a function handler and expect matcher toHaveBeenCalledWith. Although the example is possible, it is not straight and forward enough on the objective of sub-object match using this asymmetric matcher based on given object.
The reproduction steps follow below:
Clone repository https://github.com/alloyha/experiments
Navigate to folder /web/test_expect;
Run command npm install;
Run command npm test;
The expected output is:
FAIL __test__/expect.test.js
● expect › assert asymmetric matcher existent objectContainingAsyMatch
expect(received).toEqual(expected) // deep equality
- Expected - 2
+ Received + 4
- ObjectContaining {
- "foo": Any<String>,
+ Object {
+ "bar": Object {
+ "foo": "baz",
+ },
}
8 | expectation = expect.objectContaining({ foo: expect.any(String) });
9 |
> 10 | expect(result).toEqual(expectation);
| ^
11 | }
12 | );
13 | }
at Object.toEqual (__test__/expect.test.js:10:28)
Test Suites: 1 failed, 1 total
Tests: 1 failed, 1 total
Snapshots: 0 total
Time: 0.163 s, estimated 1 s
Ran all test suites.
This question already has answers here:
Why doesn't println! work in Rust unit tests?
(9 answers)
Closed 2 years ago.
Ink :: What is the right way to add the debug trace prints | ink_env::debug_println ?
Was trying ERC20 sample example from https://substrate.dev/substrate-contracts-workshop/#/2/transferring-tokens
#[ink(message)]
pub fn transfer(&mut self, to: AccountId, value: Balance) -> bool {
// ACTION: Call the `transfer_from_to` with `from` as `self.env().caller()`
let source: AccountId = self.env().caller();
let dbg_msg = format!( "from {:#?} to {:#?}", source, to );
ink_env::debug_println( &dbg_msg );
self.transfer_from_to( source , to, value )
}
With trace prints, executed the test, but can't see the trace output.
$ cargo +nightly test
Compiling erc20 v0.1.0 (/tmp/tmp.MkRICOxro3/erc20)
Finished test [unoptimized + debuginfo] target(s) in 0.85s
Running target/debug/deps/erc20-ac25c678251cab02
running 3 tests
test erc20::tests::balance_works ... ok
test erc20::tests::new_works ... ok
test erc20::tests::transfer_works ... ok
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Note:: Complete code snippet is at path ...
https://gist.github.com/shamb0/aee23b7f4789b0cd57cbc1c8f3fa2538
By default, Rust hides the stdout of successful tests.
To override this, use the --nocapture flag when running your test:
cargo +nightly test -- --nocapture
If I write the following code in Promela and run it in Spin in verifier mode it ends with 0 errors. It does report that toogle and init had unreached states, but those seem to be only warnings.
byte x = 0; byte y = 0;
active proctype toggle() {
do
:: x == 1 -> x = 0
:: x == 0 -> x = 1
od
}
init {
(y == 1);
}
I was confused by this because I thought this would give me a 'invalid end state' error. If I change the body of the toogle proctype with a simple skip statement it does error out as I expected.
Why is this? Is there a way to force the simulator to report the infinite loop as an error?
Regarding the 'unreached in proctype' messages, adding an end label to the do loop doesn't seem to do anything.
I am running spin 6.5.0 and ran the following commands:
spin.exe -a test.pml
gcc -o pan pan.c
pan.exe
These are the outputs, for reference.
With do loop:
pan.exe
(Spin Version 6.5.0 -- 1 July 2019)
+ Partial Order Reduction
Full statespace search for:
never claim - (none specified)
assertion violations +
acceptance cycles - (not selected)
invalid end states +
State-vector 20 byte, depth reached 3, errors: 0
4 states, stored
1 states, matched
5 transitions (= stored+matched)
0 atomic steps
hash conflicts: 0 (resolved)
Stats on memory usage (in Megabytes):
0.000 equivalent memory usage for states (stored*(State-vector + overhead))
0.292 actual memory usage for states
64.000 memory used for hash table (-w24)
0.343 memory used for DFS stack (-m10000)
64.539 total actual memory usage
unreached in proctype toggle
..\test2.pml:7, state 8, "-end-"
(1 of 8 states)
unreached in init
..\test2.pml:10, state 2, "-end-"
(1 of 2 states)
pan: elapsed time 0.013 seconds
pan: rate 307.69231 states/second
With skip:
pan.exe
pan:1: invalid end state (at depth 0)
pan: wrote ..\test2.pml.trail
(Spin Version 6.5.0 -- 1 July 2019)
Warning: Search not completed
+ Partial Order Reduction
Full statespace search for:
never claim - (none specified)
assertion violations +
acceptance cycles - (not selected)
invalid end states +
State-vector 20 byte, depth reached 1, errors: 1
2 states, stored
0 states, matched
2 transitions (= stored+matched)
0 atomic steps
hash conflicts: 0 (resolved)
Stats on memory usage (in Megabytes):
0.000 equivalent memory usage for states (stored*(State-vector + overhead))
0.293 actual memory usage for states
64.000 memory used for hash table (-w24)
0.343 memory used for DFS stack (-m10000)
64.539 total actual memory usage
pan: elapsed time 0.015 seconds
pan: rate 133.33333 states/second
In this example
byte x = 0; byte y = 0;
active proctype toggle() {
do
:: x == 1 -> x = 0
:: x == 0 -> x = 1
od
}
init {
(y == 1);
}
the init process is blocked forever (because y == 1 is always false), but the toggle process can always execute something. Therefore, there is no invalid end state error.
Instead, in this example
byte x = 0; byte y = 0;
active proctype toggle() {
skip;
}
init {
(y == 1);
}
the init process is still blocked forever, but the toggle process can execute its only instruction skip; and then terminate. At this point, none of the remaining processes (i.e. only init) has any instruction it can execute, so Spin terminates with an invalid end state error.
~$ spin -a -search test.pml
pan:1: invalid end state (at depth 0)
pan: wrote test.pml.trail
(Spin Version 6.5.0 -- 17 July 2019)
...
State-vector 20 byte, depth reached 1, errors: 1
...
Is there a way to force the simulator to report the infinite loop as an error?
Yes. There are actually multiple ways.
The simplest approach is to use option -l of Spin:
~$ spin --help
...
-l: search for non-progress cycles
...
With this option, Spin reports any infinite-loop which does not contain any state with a progress label.
This is the output on your original problem:
~$ spin -search -l test.pml
pan:1: non-progress cycle (at depth 2)
pan: wrote test.pml.trail
(Spin Version 6.5.0 -- 17 July 2019)
...
State-vector 28 byte, depth reached 9, errors: 1
...
~$ spin -t test.pml
spin: couldn't find claim 2 (ignored)
<<<<<START OF CYCLE>>>>>
spin: trail ends after 10 steps
#processes: 2
x = 0
y = 0
10: proc 1 (:init::1) test.pml:10 (state 1)
10: proc 0 (toggle:1) test.pml:5 (state 4)
2 processes created
An alternative approach is to use LTL model checking. For instance, you may state that at some point the number of processes (see _nr_pr) that are in execution becomes equal to 0 (or more, if you admit some infinite loops), or check that a particular process terminates correctly using remote references.
Both cases are contained in the following example:
byte x = 0; byte y = 0;
active proctype toggle() {
do
:: x == 1 -> x = 0
:: x == 0 -> x = 1
od;
end:
}
init {
(y == 1);
}
// sooner or later, the process toggle
// with _pid == 0 will reach the end
// state
ltl p1 { <> toggle[0]#end };
// sooner or later, the number of processes
// that are currently running becomes 0,
// (hence, there can be no infinite loops)
ltl p2 { <> (_nr_pr == 0) };
Both the first
~$ spin -a -search -ltl p1 test.pml
~$ spin -t test.pml
ltl p1: <> ((toggle[0]#end))
ltl p2: <> ((_nr_pr==0))
<<<<<START OF CYCLE>>>>>
Never claim moves to line 4 [(!((toggle[0]._p==end)))]
spin: trail ends after 8 steps
#processes: 2
x = 0
y = 0
end = 0
8: proc 1 (:init::1) test.pml:10 (state 1)
8: proc 0 (toggle:1) test.pml:3 (state 5)
8: proc - (p1:1) _spin_nvr.tmp:3 (state 3)
2 processes created
and the second
~$ spin -a -search -ltl p2 test.pml
~$ spin -t test.pml
ltl p1: <> ((toggle[0]#end))
ltl p2: <> ((_nr_pr==0))
<<<<<START OF CYCLE>>>>>
Never claim moves to line 11 [(!((_nr_pr==0)))]
spin: trail ends after 8 steps
#processes: 2
x = 0
y = 0
end = 0
8: proc 1 (:init::1) test.pml:10 (state 1)
8: proc 0 (toggle:1) test.pml:3 (state 5)
8: proc - (p2:1) _spin_nvr.tmp:10 (state 3)
2 processes created
LTL properties are found to be false.
Regarding the 'unreached in proctype' messages, adding an end label to the do loop doesn't seem to do anything.
The end label(s) are used to remove the "invalid end state" error that would be otherwise be found.
For example, modifying your previous example as follows:
byte x = 0; byte y = 0;
active proctype toggle() {
skip;
}
init {
end:
(y == 1);
}
Makes the error go away:
~$ spin -a -search test.pml
(Spin Version 6.5.0 -- 17 July 2019)
...
State-vector 20 byte, depth reached 1, errors: 0
...
One should only ever use an end label when one is willing to guarantee that a process being stuck with no executable instruction is not a symptom of an undesired deadlock situation.
I'm playing a bit with NativeCall to get familiar with that side of Perl6. Of course, I'm trying to load libstatgrab first (what else?).
So I start with easiest part - the host information. Since no cluster support yet, it's just one result - no worries for complication.
The code:
#!/usr/bin/env perl6
use v6;
use NativeCall;
enum sg_error (
SG_ERROR_NONE => 0,
SG_ERROR_INVALID_ARGUMENT => 1,
...
);
class sg_error_details is repr('CStruct') {
has int32 $.error;
has int32 $.errno_value;
has Str $.error_arg;
};
sub sg_init(int32 $ignore_errors) returns int32 is native('statgrab') { * };
enum sg_host_state (
sg_unknown_configuration => 0,
sg_physical_host => 1,
sg_virtual_machine => 2,
sg_paravirtual_machine => 3,
sg_hardware_virtualized => 4
);
class sg_host_info is repr('CStruct') {
has Str $.os_name;
has Str $.os_release;
has Str $.os_version;
has Str $.platform;
has Str $.hostname;
has uint32 $.bitwidth;
has int32 $.host_state;
has uint32 $.ncpus;
has uint32 $.maxcpus;
has uint64 $.uptime;
has uint64 $.systime;
};
sub sg_get_host_info(size_t is rw) returns Pointer is native('statgrab') is symbol('sg_get_host_info_r') { * };
sub sg_free_host_info(Pointer) is native('statgrab') is symbol('sg_free_stats_buf') { * };
sub MAIN() {
my int32 $ignore_errors = 0;
my $error = sg_init($ignore_errors);
if $error != SG_ERROR_NONE {
say "Maeh: $error";
exit 1;
}
my size_t $num_host_infos = 0;
my $res = sg_get_host_info($num_host_infos);
if $num_host_infos > 0 {
my $host_info = nativecast(sg_host_info, $res);
with $host_info {
say "You're using ", $_.os_name, " on ", $_.hostname;
}
}
sg_free_host_info($res);
}
Starting it (dumb) results in loading library error:
$ perl6 statgrab.p6
Cannot locate native library 'libstatgrab.dylib': dlopen(libstatgrab.dylib, 1): image not found
in method setup at /Users/sno/rakudo/share/perl6/sources/24DD121B5B4774C04A7084827BFAD92199756E03 (NativeCall) line 283
in method CALL-ME at /Users/sno/rakudo/share/perl6/sources/24DD121B5B4774C04A7084827BFAD92199756E03 (NativeCall) line 570
in sub MAIN at statgrab.p6 line 95
in block <unit> at statgrab.p6 line 93
Okay - giving it some search path:
$ LD_LIBRARY_PATH=/opt/pkg/lib:$LD_LIBRARY_PATH perl6 statgrab.p6
Cannot locate native library 'libstatgrab.dylib': dlopen(libstatgrab.dylib, 1): image not found
Same picture when using DYLD_LIBRARY_PATH - which is supported by dlopen(3) on Darwin, too.
But changing in the directory works:
$ (cd /opt/pkg/lib && perl6 /data/Projects/OSS/p6-Unix-Statgrab/statgrab.p6 )
You're using Darwin on ernie.[...]
Is there a lack of search path passthrough in the way how moarvm is called?
doug$ perl6 -v
This is Rakudo Star version 2018.10 built on MoarVM version 2018.10
implementing Perl 6.c.
On a fairly recent Rakudo Star on MacOS High Sierra, the script worked "out of the box" for me:
edited script to remove '...'.
Script failed to load the library (really missing!)
brew install libstatgrab
Script ran successfully:
vader:learning doug$ perl6 nativecall_mac_Sno.pl6
You're using Darwin on Vader.local
Homebrew installed the library as follows:
$ v /usr/local/lib
total 11904
-rw-r--r-- 1 doug admin 6080828 Sep 23 12:40 libmoar.dylib
lrwxr-xr-x 1 doug admin 51 Mar 23 11:02 libstatgrab.10.dylib# -> ../Cellar/libstatgrab/0.91/lib/libstatgrab.10.dylib
lrwxr-xr-x 1 doug admin 44 Mar 23 11:02 libstatgrab.a# -> ../Cellar/libstatgrab/0.91/lib/libstatgrab.a
lrwxr-xr-x 1 doug admin 48 Mar 23 11:02 libstatgrab.dylib# -> ../Cellar/libstatgrab/0.91/lib/libstatgrab.dylib
drwxr-xr-x 3 doug admin 102 Mar 23 11:02 pkgconfig/
For me, the perl6 executable is indeed a shell script, but it worked (there was no need to pass any extra LD_LIBRARY_PATH=...).
doug$ file `which perl6`
/Applications/Rakudo/bin/perl6: POSIX shell script text executable, ASCII text, with very long lines
doug$ set | grep LIBRARY
doug$
I have also had issues with my nativecall scripts finding the library, but have always solved them by fixing the library install and/or supplying 'LD_LIBRARY_PATH'.
Sorry this experience was Less Than Awesome for you
I am iterating over a hash of arrays in one of my puppet manifests
1 # class to manage needed packages
2 class profile::packages (
3 ){
4 $packages = hiera_hash('profile::packages::managed', {})
5
6 if $packages != {} {
7 $packages.each | String $package_state, Array $packages_array | {
8 $packages_array.each | Integer $idx, String $package | {
9 notify { "${package} with ${idx} should be ${package_state}": }
10 }
11 }
12 }
13 }
but I get a puppet-lint warning.
WARNING: top-scope variable being used without an explicit namespace
on line 8
Blockquote
WARNING: top-scope variable being used without an explicit
namespace on line 9
The code is running well, so it's a question of puppet-lint. Maybe there is a way to configure puppet-lint to recognize variables in the lambda blocks?
This is a known issue in puppet-lint at the time of writing. It has limited support for Puppet 4 language features.