blackstack-nodes 1.2.14 → 1.2.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/blackstack-nodes.rb +29 -16
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ed42ce28e323788e17215ca87fc900d25493a140adce92d38c5eac9d0469ce8
4
- data.tar.gz: 4de3f22c58fb77ea176e6697594be8f44beb4079d1acb6b2a5e722f46be3ddd3
3
+ metadata.gz: baa210daeea5b1e58fb15147e50003cef8e154085926c2b85cc80701965d3c92
4
+ data.tar.gz: d68c0e01dcd790b4bc3032f25bc7b8159cb1287260ce7c41b00eed02ee176553
5
5
  SHA512:
6
- metadata.gz: a0ca565b5076a4c50f1a7ac8ceacc81821ffa6147795c3ee24427e115910fe57f7ca6794a153358498fa6f96020619fafa22d48c34b137d2280c94a2b6489114
7
- data.tar.gz: '080428a73ccbb5b9cb189b32ea114ec9f7e1c93ec3a266ba42f5e21aed39566cf00616eb3d97bde1460dc1f9dd8ebaebd641894840c3836949492d15d75c1390'
6
+ metadata.gz: 74e04021b9f39eb587a0a2471e2bf1406dca2be895e65af0316c0dc89a94652148ac1a16c6ab5b16cc073f5b4cfa0bbf0414e13961357e5695e7a834e98eeec8
7
+ data.tar.gz: ab8d5169af5376d2c6e52251a4b1e4b76c9e45187ec1db42dd18741a8eaf1a2865293bfda6f68bdb279f42ed9ea75b617240dfe70eab04ff09992ef3182c6dea
@@ -117,31 +117,44 @@ module BlackStack
117
117
  self.ssh.close
118
118
  end
119
119
 
120
+ # Execute a command on the remote server and return the output.
121
+ # If the exit code of the command is not zero, an exception is raised, with the messages pushed into the stderr.
122
+ # If the exit code of the command is zero, the messages pushed into the stdout are returned.
123
+ #
124
+ # IMPORTANT: Messages pushed into stderr re not always error.
125
+ # Reference:
126
+ # - How to stop git from writing non-errors to stderr ?
127
+ # - https://stackoverflow.com/questions/57016157/how-to-stop-git-from-writing-non-errors-to-stderr
128
+ #
120
129
  def exec(
121
130
  command,
122
- output_file: "~/bash-command-stdout-buffer",
123
- error_file: "~/bash-command-stderr-buffer"
131
+ output_file: "~/.bash-command-stdout-buffer",
132
+ error_file: "~/.bash-command-stderr-buffer",
133
+ exit_code_file: "~/.bash-command-exit-code"
124
134
  )
125
- # Construct the remote command with redirection for stdout and stderr
126
- remote_command = "#{command} > #{output_file} 2> #{error_file}"
127
-
128
- # Execute the command on the remote server
129
- self.ssh.exec!("truncate -s 0 #{output_file} #{error_file} && #{remote_command}")
130
-
135
+ # Construct the remote command with redirection for stdout, stderr, and capturing exit code
136
+ remote_command = "#{command} > #{output_file} 2> #{error_file}; echo $? > #{exit_code_file}"
137
+
138
+ # Execute the command on the remote server, truncating output, error, and exit code files
139
+ self.ssh.exec!("truncate -s 0 #{output_file} #{error_file} #{exit_code_file} && #{remote_command}")
140
+
141
+ # Retrieve the exit code
142
+ exit_code = self.ssh.exec!("cat #{exit_code_file}").to_s.chomp.to_i
143
+
131
144
  # Retrieve the content of the error file from the remote server
132
145
  error_content = self.ssh.exec!("cat #{error_file}").to_s.chomp
133
-
134
- # Check if the error file has any content
135
- unless error_content.empty?
146
+
147
+ # Check if the exit code is not zero
148
+ if exit_code != 0
136
149
  # Raise an exception with the error message
137
- raise "Command failed with the following error:\n#{error_content}"
150
+ raise "Command failed with exit code #{exit_code}:\n#{error_content}"
138
151
  end
139
-
152
+
140
153
  # Retrieve and return the content of the output file from the remote server
141
- # truncate any last newline character
154
+ # Truncate any trailing newline character
142
155
  self.ssh.exec!("cat #{output_file}").to_s.chomp
143
- end
144
-
156
+ end # def exec
157
+
145
158
  def reboot()
146
159
  tries = 0
147
160
  max_tries = 20
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blackstack-nodes
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.14
4
+ version: 1.2.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leandro Daniel Sardi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-09-13 00:00:00.000000000 Z
11
+ date: 2024-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh