Skip to content

Commit f37ee1a

Browse files
Merge pull request #5753 from cfengine/ENT-12729/master
Moved isconnectable example to acceptance test since it needs to be complicated to work
2 parents f421fc6 + dd593c0 commit f37ee1a

File tree

2 files changed

+44
-7
lines changed

2 files changed

+44
-7
lines changed

examples/isconnectable.cf

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ body common control
2525
{
2626
bundlesequence => { "example" };
2727
}
28-
bundle agent example
28+
bundle agent example
2929
{
3030
classes:
3131
"isconnectable" expression => isconnectable("localhost", 22, "30");
@@ -37,9 +37,3 @@ bundle agent example
3737
"Port is not connectable";
3838
}
3939
#+end_src
40-
###############################################################################
41-
#+begin_src example_output
42-
#@ ```
43-
#@ R: Port is connectable
44-
#@ ```
45-
#+end_src
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
body common control
2+
{
3+
inputs => { "../../default.cf.sub" };
4+
bundlesequence => { default("$(this.promise_filename)") };
5+
version => "1.0";
6+
}
7+
8+
bundle agent init
9+
{
10+
vars:
11+
# to avoid dependencies (like installing netstat/net-utils), look at proc filesystem for listening port, probably at least one (like ssh or chrony)
12+
# header of /proc/net/tcp is: sl local_address rem_address st tx_queue rx_queue tr tm->when retrnsmt uid timeout inode
13+
# local_address is ip:port
14+
# example line for ssh (port 22, hex 16): 0: 00000000:0016 00000000:0000 0A 00000000:00000000 00:00000000 00000000 0 0 25575 2 ffff9eac03038000 100 0 0 10 0
15+
# finally, to keep things "simple" only try ports listening on 0.0.0.0 aka 00000000: in the local_address column
16+
"port_to_check" string => execresult("cat /proc/net/tcp | grep ': 00000000:' | head -2 | tail -1 | awk '{print $2}' | cut -d: -f2 | xargs -I{} printf '%d\n' 0x{}", "useshell");
17+
18+
classes:
19+
"port_to_check_available" expression => and(
20+
isvariable("port_to_check"),
21+
not(strcmp("${port_to_check}",""))
22+
),
23+
scope => "namespace";
24+
25+
reports:
26+
"init bundle, port_to_check is ${port_to_check}";
27+
}
28+
29+
bundle agent check
30+
{
31+
meta:
32+
"test_skip_unsupported" string => "!linux|!port_to_check_available";
33+
34+
classes:
35+
"isconnectable" expression => isconnectable("localhost", ${init.port_to_check}, "30");
36+
37+
reports:
38+
"Tried isconnectable on port_to_check ${init.port_to_check}";
39+
isconnectable::
40+
"${this.promise_filename} Pass";
41+
!isconnectable::
42+
"${this.promise_filename} FAIL";
43+
}

0 commit comments

Comments
 (0)