wavefront-cli 4.2.1 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/.rubocop.yml +1 -14
- data/.travis.yml +4 -4
- data/Gemfile +2 -0
- data/HISTORY.md +82 -60
- data/Rakefile +2 -0
- data/bin/wf +1 -0
- data/lib/wavefront-cli/alert.rb +13 -5
- data/lib/wavefront-cli/apitoken.rb +2 -0
- data/lib/wavefront-cli/base.rb +95 -47
- data/lib/wavefront-cli/cloudintegration.rb +6 -0
- data/lib/wavefront-cli/command_mixins/acl.rb +6 -1
- data/lib/wavefront-cli/command_mixins/tag.rb +2 -0
- data/lib/wavefront-cli/commands/.rubocop.yml +3 -4
- data/lib/wavefront-cli/commands/alert.rb +2 -1
- data/lib/wavefront-cli/commands/apitoken.rb +6 -0
- data/lib/wavefront-cli/commands/base.rb +30 -21
- data/lib/wavefront-cli/commands/cloudintegration.rb +2 -0
- data/lib/wavefront-cli/commands/config.rb +2 -0
- data/lib/wavefront-cli/commands/dashboard.rb +2 -0
- data/lib/wavefront-cli/commands/derivedmetric.rb +2 -0
- data/lib/wavefront-cli/commands/event.rb +3 -1
- data/lib/wavefront-cli/commands/integration.rb +2 -1
- data/lib/wavefront-cli/commands/link.rb +2 -0
- data/lib/wavefront-cli/commands/message.rb +2 -0
- data/lib/wavefront-cli/commands/metric.rb +2 -0
- data/lib/wavefront-cli/commands/notificant.rb +2 -0
- data/lib/wavefront-cli/commands/proxy.rb +2 -0
- data/lib/wavefront-cli/commands/query.rb +2 -0
- data/lib/wavefront-cli/commands/savedsearch.rb +2 -0
- data/lib/wavefront-cli/commands/serviceaccount.rb +58 -0
- data/lib/wavefront-cli/commands/settings.rb +2 -0
- data/lib/wavefront-cli/commands/source.rb +3 -1
- data/lib/wavefront-cli/commands/user.rb +4 -1
- data/lib/wavefront-cli/commands/usergroup.rb +3 -0
- data/lib/wavefront-cli/commands/webhook.rb +2 -0
- data/lib/wavefront-cli/commands/window.rb +2 -0
- data/lib/wavefront-cli/commands/write.rb +2 -0
- data/lib/wavefront-cli/config.rb +23 -12
- data/lib/wavefront-cli/constants.rb +10 -4
- data/lib/wavefront-cli/controller.rb +53 -22
- data/lib/wavefront-cli/dashboard.rb +3 -0
- data/lib/wavefront-cli/derivedmetric.rb +12 -11
- data/lib/wavefront-cli/display/alert.rb +7 -4
- data/lib/wavefront-cli/display/apitoken.rb +2 -0
- data/lib/wavefront-cli/display/base.rb +34 -8
- data/lib/wavefront-cli/display/cloudintegration.rb +4 -2
- data/lib/wavefront-cli/display/dashboard.rb +2 -0
- data/lib/wavefront-cli/display/derivedmetric.rb +2 -0
- data/lib/wavefront-cli/display/distribution.rb +2 -0
- data/lib/wavefront-cli/display/event.rb +2 -0
- data/lib/wavefront-cli/display/externallink.rb +2 -0
- data/lib/wavefront-cli/display/integration.rb +2 -0
- data/lib/wavefront-cli/display/maintenancewindow.rb +2 -0
- data/lib/wavefront-cli/display/message.rb +7 -3
- data/lib/wavefront-cli/display/metric.rb +3 -1
- data/lib/wavefront-cli/display/notificant.rb +3 -1
- data/lib/wavefront-cli/display/printer/long.rb +36 -11
- data/lib/wavefront-cli/display/printer/sparkline.rb +3 -0
- data/lib/wavefront-cli/display/printer/terse.rb +6 -1
- data/lib/wavefront-cli/display/proxy.rb +2 -0
- data/lib/wavefront-cli/display/query.rb +35 -24
- data/lib/wavefront-cli/display/savedsearch.rb +2 -0
- data/lib/wavefront-cli/display/serviceaccount.rb +60 -0
- data/lib/wavefront-cli/display/settings.rb +2 -0
- data/lib/wavefront-cli/display/source.rb +18 -4
- data/lib/wavefront-cli/display/user.rb +56 -10
- data/lib/wavefront-cli/display/usergroup.rb +25 -19
- data/lib/wavefront-cli/display/webhook.rb +2 -0
- data/lib/wavefront-cli/display/write.rb +6 -2
- data/lib/wavefront-cli/event.rb +83 -62
- data/lib/wavefront-cli/exception.rb +3 -0
- data/lib/wavefront-cli/externallink.rb +6 -4
- data/lib/wavefront-cli/integration.rb +2 -0
- data/lib/wavefront-cli/maintenancewindow.rb +28 -17
- data/lib/wavefront-cli/message.rb +4 -0
- data/lib/wavefront-cli/metric.rb +4 -1
- data/lib/wavefront-cli/notificant.rb +2 -0
- data/lib/wavefront-cli/opt_handler.rb +2 -0
- data/lib/wavefront-cli/output/base.rb +8 -3
- data/lib/wavefront-cli/output/csv.rb +2 -0
- data/lib/wavefront-cli/output/csv/base.rb +2 -0
- data/lib/wavefront-cli/output/csv/query.rb +14 -7
- data/lib/wavefront-cli/output/hcl.rb +2 -0
- data/lib/wavefront-cli/output/hcl/alert.rb +2 -0
- data/lib/wavefront-cli/output/hcl/base.rb +10 -4
- data/lib/wavefront-cli/output/hcl/dashboard.rb +17 -8
- data/lib/wavefront-cli/output/hcl/notificant.rb +2 -0
- data/lib/wavefront-cli/output/hcl/stdlib/array.rb +2 -0
- data/lib/wavefront-cli/output/hcl/stdlib/string.rb +2 -0
- data/lib/wavefront-cli/output/json.rb +2 -0
- data/lib/wavefront-cli/output/ruby.rb +2 -0
- data/lib/wavefront-cli/output/wavefront.rb +2 -0
- data/lib/wavefront-cli/output/wavefront/query.rb +7 -4
- data/lib/wavefront-cli/output/yaml.rb +2 -0
- data/lib/wavefront-cli/proxy.rb +15 -3
- data/lib/wavefront-cli/query.rb +14 -12
- data/lib/wavefront-cli/savedsearch.rb +2 -0
- data/lib/wavefront-cli/serviceaccount.rb +179 -0
- data/lib/wavefront-cli/settings.rb +2 -0
- data/lib/wavefront-cli/source.rb +2 -0
- data/lib/wavefront-cli/stdlib/array.rb +3 -0
- data/lib/wavefront-cli/stdlib/string.rb +17 -11
- data/lib/wavefront-cli/user.rb +10 -4
- data/lib/wavefront-cli/usergroup.rb +4 -2
- data/lib/wavefront-cli/version.rb +3 -1
- data/lib/wavefront-cli/webhook.rb +2 -0
- data/lib/wavefront-cli/write.rb +80 -46
- data/spec/.rubocop.yml +3 -16
- data/spec/constants.rb +21 -0
- data/spec/spec_helper.rb +8 -422
- data/spec/support/command_base.rb +82 -0
- data/spec/support/minitest_assertions.rb +262 -0
- data/spec/support/output_tester.rb +32 -0
- data/spec/support/supported_commands.rb +19 -0
- data/spec/test_mixins/acl.rb +169 -0
- data/spec/test_mixins/delete.rb +25 -0
- data/spec/test_mixins/deleteundelete.rb +106 -0
- data/spec/test_mixins/describe.rb +24 -0
- data/spec/test_mixins/dump.rb +43 -0
- data/spec/test_mixins/general.rb +11 -0
- data/spec/test_mixins/history.rb +35 -0
- data/spec/test_mixins/import.rb +65 -0
- data/spec/test_mixins/list.rb +29 -0
- data/spec/test_mixins/search.rb +98 -0
- data/spec/test_mixins/set.rb +47 -0
- data/spec/test_mixins/tag.rb +99 -0
- data/spec/wavefront-cli/alert_spec.rb +288 -111
- data/spec/wavefront-cli/apitoken_spec.rb +53 -24
- data/spec/wavefront-cli/base_spec.rb +9 -27
- data/spec/wavefront-cli/cloudintegration_spec.rb +65 -29
- data/spec/wavefront-cli/commands/alert_spec.rb +1 -0
- data/spec/wavefront-cli/commands/base_spec.rb +15 -13
- data/spec/wavefront-cli/commands/cloudintegration_spec.rb +1 -0
- data/spec/wavefront-cli/commands/config_spec.rb +3 -0
- data/spec/wavefront-cli/commands/dashboard_spec.rb +1 -0
- data/spec/wavefront-cli/commands/derivedmetric_spec.rb +1 -0
- data/spec/wavefront-cli/commands/event_spec.rb +1 -0
- data/spec/wavefront-cli/commands/link_spec.rb +1 -0
- data/spec/wavefront-cli/commands/message_spec.rb +1 -0
- data/spec/wavefront-cli/commands/metric_spec.rb +1 -0
- data/spec/wavefront-cli/commands/proxy_spec.rb +1 -0
- data/spec/wavefront-cli/commands/query_spec.rb +1 -0
- data/spec/wavefront-cli/commands/webhook_spec.rb +1 -0
- data/spec/wavefront-cli/commands/window_spec.rb +1 -0
- data/spec/wavefront-cli/commands/write_spec.rb +1 -0
- data/spec/wavefront-cli/config_spec.rb +25 -14
- data/spec/wavefront-cli/controller_spec.rb +13 -3
- data/spec/wavefront-cli/dashboard_spec.rb +125 -76
- data/spec/wavefront-cli/derivedmetric_spec.rb +83 -67
- data/spec/wavefront-cli/display/base_spec.rb +5 -7
- data/spec/wavefront-cli/display/printer/long_spec.rb +20 -16
- data/spec/wavefront-cli/display/printer/terse_spec.rb +5 -4
- data/spec/wavefront-cli/event_spec.rb +360 -18
- data/spec/wavefront-cli/externallink_spec.rb +92 -58
- data/spec/wavefront-cli/integration_spec.rb +129 -31
- data/spec/wavefront-cli/maintenancewindow_spec.rb +270 -32
- data/spec/wavefront-cli/message_spec.rb +73 -30
- data/spec/wavefront-cli/metric_spec.rb +60 -22
- data/spec/wavefront-cli/notificant_spec.rb +45 -32
- data/spec/wavefront-cli/opt_handler_spec.rb +4 -1
- data/spec/wavefront-cli/output/csv/query_spec.rb +21 -19
- data/spec/wavefront-cli/output/csv_spec.rb +5 -2
- data/spec/wavefront-cli/output/hcl_spec.rb +5 -2
- data/spec/wavefront-cli/output/helpers.rb +18 -0
- data/spec/wavefront-cli/output/json_spec.rb +3 -1
- data/spec/wavefront-cli/output/ruby_spec.rb +3 -1
- data/spec/wavefront-cli/output/wavefront/query_spec.rb +3 -1
- data/spec/wavefront-cli/output/wavefront_spec.rb +6 -4
- data/spec/wavefront-cli/output/yaml_spec.rb +3 -1
- data/spec/wavefront-cli/proxy_spec.rb +49 -27
- data/spec/wavefront-cli/query_spec.rb +174 -92
- data/spec/wavefront-cli/resources/responses/query.json +1 -0
- data/spec/wavefront-cli/resources/updates/alert.json +15 -0
- data/spec/wavefront-cli/resources/updates/dashboard.json +1 -0
- data/spec/wavefront-cli/savedsearch_spec.rb +35 -18
- data/spec/wavefront-cli/serviceaccount_spec.rb +399 -0
- data/spec/wavefront-cli/settings_spec.rb +42 -11
- data/spec/wavefront-cli/source_spec.rb +120 -23
- data/spec/wavefront-cli/stdlib/array_spec.rb +2 -1
- data/spec/wavefront-cli/stdlib/string_spec.rb +9 -6
- data/spec/wavefront-cli/user_spec.rb +278 -108
- data/spec/wavefront-cli/usergroup_spec.rb +152 -102
- data/spec/wavefront-cli/webhook_spec.rb +30 -15
- data/spec/wavefront-cli/write_spec.rb +25 -1
- data/wavefront-cli.gemspec +5 -3
- metadata +65 -21
- data/spec/wavefront-cli/commands/spec_helper.rb +0 -3
- data/spec/wavefront-cli/display/spec_helper.rb +0 -3
@@ -1,45 +1,143 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
word = 'integration'
|
4
|
+
require_relative '../support/command_base'
|
5
|
+
require_relative '../../lib/wavefront-cli/integration'
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
# Ensure 'integration' commands produce the correct API calls.
|
8
|
+
#
|
9
|
+
class IntegrationEndToEndTest < EndToEndTest
|
10
|
+
include WavefrontCliTest::List
|
11
|
+
include WavefrontCliTest::Describe
|
12
|
+
include WavefrontCliTest::Search
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
cmd_to_call(word, "status #{id}", path: "/api/v2/#{word}/#{id}/status")
|
14
|
+
def test_install
|
15
|
+
quietly do
|
16
|
+
assert_cmd_posts("install #{id}",
|
17
|
+
"/api/v2/integration/#{id}/install",
|
18
|
+
'null')
|
19
|
+
end
|
17
20
|
|
18
|
-
|
19
|
-
|
21
|
+
assert_invalid_id("install #{invalid_id}")
|
22
|
+
assert_usage('install')
|
23
|
+
assert_abort_on_missing_creds("install #{id}")
|
20
24
|
|
21
|
-
|
22
|
-
|
25
|
+
assert_noop("install #{id}",
|
26
|
+
'uri: POST https://default.wavefront.com/api/v2/' \
|
27
|
+
"integration/#{id}/install",
|
28
|
+
'body: null')
|
29
|
+
end
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
def test_uninstall
|
32
|
+
quietly do
|
33
|
+
assert_cmd_posts("uninstall #{id}",
|
34
|
+
"/api/v2/integration/#{id}/uninstall",
|
35
|
+
'null')
|
36
|
+
end
|
27
37
|
|
28
|
-
|
29
|
-
|
30
|
-
|
38
|
+
assert_invalid_id("uninstall #{invalid_id}")
|
39
|
+
assert_usage('uninstall')
|
40
|
+
assert_abort_on_missing_creds("uninstall #{id}")
|
31
41
|
|
32
|
-
|
42
|
+
assert_noop("uninstall #{id}",
|
43
|
+
'uri: POST https://default.wavefront.com/api/v2/' \
|
44
|
+
"integration/#{id}/uninstall",
|
45
|
+
'body: null')
|
46
|
+
end
|
33
47
|
|
34
|
-
|
48
|
+
def test_manifests
|
49
|
+
assert_exits_with('Human-readable manifest output is not supported.',
|
50
|
+
'manifests -f human')
|
35
51
|
|
36
|
-
|
52
|
+
quietly do
|
53
|
+
assert_cmd_gets('manifests -f json', '/api/v2/integration/manifests')
|
54
|
+
end
|
37
55
|
|
38
|
-
|
56
|
+
assert_noop('manifests --format yaml',
|
57
|
+
'uri: GET https://default.wavefront.com/api/v2/' \
|
58
|
+
'integration/manifests')
|
59
|
+
assert_abort_on_missing_creds('manifests')
|
60
|
+
end
|
39
61
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
62
|
+
def test_status
|
63
|
+
quietly do
|
64
|
+
assert_cmd_gets("status #{id}", "/api/v2/integration/#{id}/status")
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_invalid_id("status #{invalid_id}")
|
68
|
+
assert_noop("status #{id}",
|
69
|
+
'uri: GET https://default.wavefront.com/api/v2/' \
|
70
|
+
"integration/#{id}/status")
|
71
|
+
assert_abort_on_missing_creds("status #{id}")
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_statuses
|
75
|
+
quietly do
|
76
|
+
assert_cmd_gets('statuses', '/api/v2/integration/status')
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_noop('statuses',
|
80
|
+
'uri: GET https://default.wavefront.com/api/v2/' \
|
81
|
+
'integration/status')
|
82
|
+
assert_abort_on_missing_creds('statuses')
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_alert_install
|
86
|
+
quietly do
|
87
|
+
assert_cmd_posts("alert install #{id}",
|
88
|
+
"/api/v2/integration/#{id}/install-all-alerts",
|
89
|
+
'null')
|
90
|
+
end
|
91
|
+
|
92
|
+
assert_invalid_id("alert install #{invalid_id}")
|
93
|
+
assert_usage('alert install')
|
94
|
+
assert_abort_on_missing_creds("alert install #{id}")
|
95
|
+
|
96
|
+
assert_noop("alert install #{id}",
|
97
|
+
'uri: POST https://default.wavefront.com/api/v2/' \
|
98
|
+
"integration/#{id}/install-all-alerts",
|
99
|
+
'body: null')
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_alert_uninstall
|
103
|
+
quietly do
|
104
|
+
assert_cmd_posts("alert uninstall #{id}",
|
105
|
+
"/api/v2/integration/#{id}/uninstall-all-alerts",
|
106
|
+
'null')
|
107
|
+
end
|
108
|
+
|
109
|
+
assert_invalid_id("alert uninstall #{invalid_id}")
|
110
|
+
assert_usage('alert uninstall')
|
111
|
+
assert_abort_on_missing_creds("alert uninstall #{id}")
|
112
|
+
|
113
|
+
assert_noop("alert uninstall #{id}",
|
114
|
+
'uri: POST https://default.wavefront.com/api/v2/' \
|
115
|
+
"integration/#{id}/uninstall-all-alerts",
|
116
|
+
'body: null')
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_installed
|
120
|
+
quietly do
|
121
|
+
assert_cmd_gets('installed', '/api/v2/integration/installed')
|
122
|
+
end
|
123
|
+
|
124
|
+
assert_noop('installed',
|
125
|
+
'uri: GET https://default.wavefront.com/api/v2/' \
|
126
|
+
'integration/installed')
|
127
|
+
assert_abort_on_missing_creds('installed')
|
128
|
+
end
|
129
|
+
|
130
|
+
private
|
131
|
+
|
132
|
+
def id
|
133
|
+
'tester'
|
134
|
+
end
|
135
|
+
|
136
|
+
def invalid_id
|
137
|
+
'%%badid%%'
|
138
|
+
end
|
139
|
+
|
140
|
+
def cmd_word
|
141
|
+
'integration'
|
142
|
+
end
|
45
143
|
end
|
@@ -1,41 +1,279 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require_relative '../
|
4
|
+
require_relative '../support/command_base'
|
4
5
|
require_relative '../../lib/wavefront-cli/maintenancewindow'
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
7
|
+
# Ensure 'window' commands produce the correct API calls.
|
8
|
+
#
|
9
|
+
class MaintenanceWindowEndToEndTest < EndToEndTest
|
10
|
+
include WavefrontCliTest::List
|
11
|
+
include WavefrontCliTest::Describe
|
12
|
+
include WavefrontCliTest::Dump
|
13
|
+
include WavefrontCliTest::Delete
|
14
|
+
# include WavefrontCliTest::Import
|
15
|
+
include WavefrontCliTest::Set
|
16
|
+
include WavefrontCliTest::Search
|
17
|
+
|
18
|
+
def test_create
|
19
|
+
quietly do
|
20
|
+
assert_cmd_posts('create -d testing --host shark test_window',
|
21
|
+
'/api/v2/maintenancewindow',
|
22
|
+
endTimeInSeconds: a_timestamp,
|
23
|
+
reason: 'testing',
|
24
|
+
relevantHostNames: %w[shark],
|
25
|
+
startTimeInSeconds: a_timestamp,
|
26
|
+
title: 'test_window')
|
27
|
+
end
|
28
|
+
|
29
|
+
assert_abort_on_missing_creds('create -d testing -H box test_window')
|
30
|
+
assert_usage('create test_window')
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_create_with_boundaries
|
34
|
+
quietly do
|
35
|
+
assert_cmd_posts('create --desc testing -H shark -s 1566776337 ' \
|
36
|
+
'-H box -e 1566776399 test_window',
|
37
|
+
'/api/v2/maintenancewindow',
|
38
|
+
endTimeInSeconds: 1_566_776_399,
|
39
|
+
reason: 'testing',
|
40
|
+
relevantHostNames: %w[shark box],
|
41
|
+
startTimeInSeconds: 1_566_776_337,
|
42
|
+
title: 'test_window')
|
43
|
+
end
|
44
|
+
|
45
|
+
assert_noop(
|
46
|
+
'create --desc testing -H shark -s 1566776337 -H box ' \
|
47
|
+
'-e 1566776399 test_window',
|
48
|
+
'uri: POST https://default.wavefront.com/api/v2/maintenancewindow',
|
49
|
+
'body: ' + { title: 'test_window',
|
50
|
+
startTimeInSeconds: 1_566_776_337,
|
51
|
+
endTimeInSeconds: 1_566_776_399,
|
52
|
+
reason: 'testing',
|
53
|
+
relevantHostNames: %w[shark box] }.to_json
|
54
|
+
)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_create_with_boundaries_and_tags
|
58
|
+
quietly do
|
59
|
+
assert_cmd_posts('create -d testing -A alert_tag_1 -A alert_tag_2 ' \
|
60
|
+
'--start 1566776337 --end 1566776399 test_window',
|
61
|
+
'/api/v2/maintenancewindow',
|
62
|
+
endTimeInSeconds: 1_566_776_399,
|
63
|
+
reason: 'testing',
|
64
|
+
relevantCustomerTags: %w[alert_tag_1 alert_tag_2],
|
65
|
+
startTimeInSeconds: 1_566_776_337,
|
66
|
+
title: 'test_window')
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_close
|
71
|
+
quietly do
|
72
|
+
all_permutations do |p|
|
73
|
+
get_stub = stub_request(
|
74
|
+
:get,
|
75
|
+
"https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
|
76
|
+
).to_return(body: canned_response.to_json, status: 200)
|
77
|
+
|
78
|
+
put_stub = stub_request(
|
79
|
+
:put,
|
80
|
+
"https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
|
81
|
+
).with(body: { id: '1538845632142',
|
82
|
+
reason: 'CLI testing',
|
83
|
+
relevantCustomerTags: [],
|
84
|
+
relevantHostTags: ['physical'],
|
85
|
+
startTimeInSeconds: 1_538_812_800,
|
86
|
+
endTimeInSeconds: a_timestamp,
|
87
|
+
title: 'test_2' })
|
88
|
+
.to_return(body: dummy_response, status: 200)
|
89
|
+
|
90
|
+
wf.new("window close #{id} #{p[:cmdline]}".split)
|
91
|
+
|
92
|
+
assert_requested(get_stub)
|
93
|
+
assert_requested(put_stub)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
assert_cannot_noop("close #{id}")
|
98
|
+
assert_abort_on_missing_creds("close #{id}")
|
99
|
+
assert_usage('close')
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_extend_to
|
103
|
+
quietly do
|
104
|
+
all_permutations do |p|
|
105
|
+
get_stub = stub_request(
|
106
|
+
:get,
|
107
|
+
"https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
|
108
|
+
).to_return(body: canned_response.to_json, status: 200)
|
109
|
+
|
110
|
+
put_stub = stub_request(
|
111
|
+
:put,
|
112
|
+
"https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
|
113
|
+
).with(body: { id: '1538845632142',
|
114
|
+
reason: 'CLI testing',
|
115
|
+
relevantCustomerTags: [],
|
116
|
+
relevantHostTags: ['physical'],
|
117
|
+
startTimeInSeconds: 1_538_812_800,
|
118
|
+
endTimeInSeconds: 1_566_781_528,
|
119
|
+
title: 'test_2' })
|
120
|
+
.to_return(body: dummy_response, status: 200)
|
121
|
+
|
122
|
+
wf.new("window extend to 1566781528 #{id} #{p[:cmdline]}".split)
|
123
|
+
|
124
|
+
assert_requested(get_stub)
|
125
|
+
assert_requested(put_stub)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
assert_cannot_noop("extend to 2:00 #{id}")
|
130
|
+
assert_usage("extend #{id} to 2:00")
|
131
|
+
assert_usage('extend')
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_extend_by
|
135
|
+
quietly do
|
136
|
+
all_permutations do |p|
|
137
|
+
get_stub = stub_request(
|
138
|
+
:get,
|
139
|
+
"https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
|
140
|
+
).to_return(body: canned_response.to_json, status: 200)
|
141
|
+
|
142
|
+
put_stub = stub_request(
|
143
|
+
:put,
|
144
|
+
"https://#{p[:endpoint]}/api/v2/maintenancewindow/#{id}"
|
145
|
+
).with(body: { id: '1538845632142',
|
146
|
+
reason: 'CLI testing',
|
147
|
+
relevantCustomerTags: [],
|
148
|
+
relevantHostTags: ['physical'],
|
149
|
+
startTimeInSeconds: 1_538_812_800,
|
150
|
+
endTimeInSeconds: a_timestamp,
|
151
|
+
title: 'test_2' })
|
152
|
+
.to_return(body: dummy_response, status: 200)
|
153
|
+
|
154
|
+
wf.new("window extend by 1h #{id} #{p[:cmdline]}".split)
|
155
|
+
|
156
|
+
assert_requested(get_stub, times: 2)
|
157
|
+
assert_requested(put_stub)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
assert_cannot_noop("extend by 1h #{id}")
|
162
|
+
assert_usage("extend 1h #{id}")
|
163
|
+
assert_usage("extend by an hour #{id}")
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_ongoing
|
167
|
+
out, err = capture_io do
|
168
|
+
assert_raises(SystemExit) do
|
169
|
+
assert_cmd_posts('ongoing',
|
170
|
+
'/api/v2/search/maintenancewindow',
|
171
|
+
state_search('ongoing').to_json)
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
assert_noop(
|
176
|
+
'ongoing',
|
177
|
+
'uri: POST https://default.wavefront.com/api/v2/search/maintenancewindow',
|
178
|
+
'body: ' + { limit: 999,
|
179
|
+
offset: 0,
|
180
|
+
query: [{ key: 'runningState',
|
181
|
+
value: 'ongoing',
|
182
|
+
matchingMethod: 'EXACT' }],
|
183
|
+
sort: { field: 'runningState',
|
184
|
+
ascending: true } }.to_json
|
185
|
+
)
|
186
|
+
|
187
|
+
assert_empty(err)
|
188
|
+
assert_equal('No maintenance windows currently ongoing.', out.strip)
|
189
|
+
assert_abort_on_missing_creds('ongoing')
|
190
|
+
end
|
191
|
+
|
192
|
+
def test_pending
|
193
|
+
out, err = capture_io do
|
194
|
+
assert_raises(SystemExit) do
|
195
|
+
assert_cmd_posts('pending',
|
196
|
+
'/api/v2/search/maintenancewindow',
|
197
|
+
state_search('pending').to_json)
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
assert_noop(
|
202
|
+
'pending',
|
203
|
+
'uri: POST https://default.wavefront.com/api/v2/search/maintenancewindow',
|
204
|
+
'body: ' + { limit: 999,
|
205
|
+
offset: 0,
|
206
|
+
query: [{ key: 'runningState',
|
207
|
+
value: 'pending',
|
208
|
+
matchingMethod: 'EXACT' }],
|
209
|
+
sort: { field: 'runningState',
|
210
|
+
ascending: true } }.to_json
|
211
|
+
)
|
212
|
+
|
213
|
+
assert_empty(err)
|
214
|
+
assert_equal('No maintenance windows in the next 24 hours.', out.strip)
|
215
|
+
assert_abort_on_missing_creds('pending')
|
216
|
+
end
|
217
|
+
|
218
|
+
private
|
219
|
+
|
220
|
+
def id
|
221
|
+
'1493324005091'
|
222
|
+
end
|
223
|
+
|
224
|
+
def invalid_id
|
225
|
+
'__BAD__'
|
226
|
+
end
|
227
|
+
|
228
|
+
def cmd_word
|
229
|
+
'window'
|
230
|
+
end
|
231
|
+
|
232
|
+
def api_path
|
233
|
+
'maintenancewindow'
|
234
|
+
end
|
235
|
+
|
236
|
+
def sdk_class_name
|
237
|
+
'MaintenanceWindow'
|
238
|
+
end
|
239
|
+
|
240
|
+
def friendly_name
|
241
|
+
'maintenance window'
|
242
|
+
end
|
243
|
+
|
244
|
+
def set_key
|
245
|
+
'title'
|
246
|
+
end
|
247
|
+
|
248
|
+
def import_fields
|
249
|
+
%i[startTimeInSeconds endTimeInSeconds relevantCustomerTags
|
250
|
+
title relevantHostTags]
|
251
|
+
end
|
29
252
|
|
30
|
-
|
31
|
-
|
32
|
-
|
253
|
+
def canned_response
|
254
|
+
{ id: '1538845632142',
|
255
|
+
reason: 'CLI testing',
|
256
|
+
customerId: 'sysdef',
|
257
|
+
relevantCustomerTags: [],
|
258
|
+
title: 'test_2',
|
259
|
+
startTimeInSeconds: 1_538_812_800,
|
260
|
+
endTimeInSeconds: 1_566_780_739,
|
261
|
+
relevantHostTags: ['physical'],
|
262
|
+
creatorId: 'rob@sysdef.xyz',
|
263
|
+
updaterId: 'rob@sysdef.xyz',
|
264
|
+
createdEpochMillis: 1_538_845_632_142,
|
265
|
+
updatedEpochMillis: 1_566_780_740_722,
|
266
|
+
eventName: 'Maintenance Window: test_2',
|
267
|
+
runningState: 'ENDED',
|
268
|
+
sortAttr: 1_000_000 }
|
33
269
|
end
|
34
270
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
271
|
+
def state_search(state)
|
272
|
+
{ limit: 999,
|
273
|
+
offset: 0,
|
274
|
+
query: [{ key: 'runningState',
|
275
|
+
value: state,
|
276
|
+
matchingMethod: 'EXACT' }],
|
277
|
+
sort: { field: 'runningState', ascending: true } }
|
40
278
|
end
|
41
279
|
end
|