stf-client 0.3.0.pre.rc.12 → 0.3.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +1 -1
- data/lib/di.rb +0 -4
- data/lib/stf/client.rb +1 -0
- data/lib/stf/errors.rb +7 -0
- data/lib/stf/interactor/get_keys_interactor.rb +2 -0
- data/lib/stf/interactor/get_values_interactor.rb +2 -0
- data/lib/stf/interactor/start_debug_session_interactor.rb +47 -64
- data/lib/stf/interactor/start_one_debug_session_interactor.rb +8 -9
- data/lib/stf/interactor/stop_all_debug_sessions_interactor.rb +8 -2
- data/lib/stf/interactor/stop_debug_session_interactor.rb +1 -0
- data/lib/stf/model/device.rb +1 -27
- data/lib/stf/model/device_list.rb +10 -38
- data/lib/stf/model/session.rb +12 -0
- data/lib/stf/version.rb +1 -1
- data/lib/stf/view/cli.rb +2 -9
- metadata +5 -4
- data/lib/stf/validate/uri_validator.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a8d5a305e07467bde680b3784cd9f60ac9bfb17e
|
4
|
+
data.tar.gz: 95496e9d6f38c47422a27d6f4b7e647a5274f032
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c70937862d2e99ae42532586d89a7c79f39a08215a6627232f0b19eef08d62552ca266e3bde21d7e20ef46e4eeaf17513bf4c33a9232611445255bf334f68d4
|
7
|
+
data.tar.gz: ff78646a4367cadc337b29e328e0ffbc6730b5a8604e6cbe2498dec695d58c099e6e0822f4f13dbbc9638b23828ec1af2a0fdf59872737ee671925e998b83e61
|
data/README.md
CHANGED
@@ -48,7 +48,7 @@ COMMANDS
|
|
48
48
|
connect - Search for a device available in STF and attach it to local adb server
|
49
49
|
disconnect - Disconnect device(s) from local adb server and remove device(s) from user devices in STF
|
50
50
|
help - Shows a list of commands or help for one command
|
51
|
-
keys - Show
|
51
|
+
keys - Show avaliable keys for filtering
|
52
52
|
values - Show known values for the filtering key
|
53
53
|
|
54
54
|
ENVIRONMENT VARIABLES
|
data/lib/di.rb
CHANGED
@@ -9,7 +9,6 @@ require 'stf/interactor/stop_all_debug_sessions_interactor'
|
|
9
9
|
require 'stf/interactor/remove_all_user_devices_interactor'
|
10
10
|
require 'stf/interactor/get_keys_interactor'
|
11
11
|
require 'stf/interactor/get_values_interactor'
|
12
|
-
require 'stf/validate/uri_validator'
|
13
12
|
|
14
13
|
class DI
|
15
14
|
class << self
|
@@ -61,9 +60,6 @@ class DI
|
|
61
60
|
-> {Stf::RemoveAllUserDevicesInteractor.new},
|
62
61
|
memoize: true)
|
63
62
|
|
64
|
-
c.register(:uri_validator,
|
65
|
-
-> {Stf::URIValidator.new},
|
66
|
-
memoize: true)
|
67
63
|
end
|
68
64
|
|
69
65
|
def [](what)
|
data/lib/stf/client.rb
CHANGED
data/lib/stf/errors.rb
ADDED
@@ -2,6 +2,8 @@ require 'ADB'
|
|
2
2
|
|
3
3
|
require 'stf/client'
|
4
4
|
require 'stf/log/log'
|
5
|
+
require 'stf/errors'
|
6
|
+
require 'stf/model/session'
|
5
7
|
require 'stf/model/device_list'
|
6
8
|
|
7
9
|
module Stf
|
@@ -17,29 +19,24 @@ module Stf
|
|
17
19
|
max_n = opts[:n].to_i > 0 ? opts[:n].to_i : 1
|
18
20
|
start_timeout = opts[:starttime].to_i > 0 ? opts[:starttime].to_i : 120
|
19
21
|
session = opts[:worktime].to_i > 0 ? opts[:session].to_i : 10800
|
20
|
-
min_n = opts[:min].to_s.empty? ? (max_n + 1) / 2 :
|
21
|
-
healthcheck = opts[:health]
|
22
|
-
force_filter = opts[:forcefilter]
|
22
|
+
min_n = opts[:min].to_s.empty? ? (max_n + 1) / 2 : opts[:min].to_i
|
23
23
|
|
24
24
|
DI[:demonizer].kill unless opts[:nokill]
|
25
25
|
|
26
|
+
if filter
|
27
|
+
DI[:stop_all_debug_sessions_interactor].execute(exceptFilter: filter)
|
28
|
+
end
|
29
|
+
|
26
30
|
wanted = nodaemon_flag ? max_n : min_n
|
27
31
|
|
28
32
|
begin
|
29
|
-
connect_loop(all_flag
|
30
|
-
wanted: wanted,
|
31
|
-
filter: filter,
|
32
|
-
force_filter: force_filter,
|
33
|
-
healthcheck: healthcheck,
|
34
|
-
delay: 5,
|
35
|
-
timeout: start_timeout)
|
36
|
-
|
33
|
+
connect_loop(all_flag, wanted, filter, false, 5, start_timeout)
|
37
34
|
rescue SignalException => e
|
38
|
-
logger.info "Caught signal
|
35
|
+
logger.info "Caught signal #{e.message}"
|
39
36
|
DI[:stop_all_debug_sessions_interactor].execute
|
40
37
|
return false
|
41
|
-
rescue
|
42
|
-
logger.info "Exception
|
38
|
+
rescue
|
39
|
+
logger.info "Exception #{e.message} during initial connect loop"
|
43
40
|
DI[:stop_all_debug_sessions_interactor].execute
|
44
41
|
return false
|
45
42
|
end
|
@@ -51,14 +48,12 @@ module Stf
|
|
51
48
|
|
52
49
|
# will be daemon here
|
53
50
|
DI[:demonizer].run do
|
54
|
-
connect_loop(all_flag
|
55
|
-
|
56
|
-
filter
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
delay: 30,
|
61
|
-
timeout: session)
|
51
|
+
connect_loop(all_flag,
|
52
|
+
max_n,
|
53
|
+
filter,
|
54
|
+
true,
|
55
|
+
30,
|
56
|
+
session)
|
62
57
|
|
63
58
|
DI[:stop_all_debug_sessions_interactor].execute(byFilter: filter, nokill: true)
|
64
59
|
end
|
@@ -66,39 +61,28 @@ module Stf
|
|
66
61
|
return true
|
67
62
|
end
|
68
63
|
|
69
|
-
def connect_loop(all_flag
|
70
|
-
wanted: 1,
|
71
|
-
|
72
|
-
filter: nil,
|
73
|
-
force_filter: false,
|
74
|
-
healthcheck: nil,
|
75
|
-
|
76
|
-
daemon_mode: false,
|
77
|
-
delay: 5,
|
78
|
-
timeout: 120)
|
64
|
+
def connect_loop(all_flag, wanted, filter, daemon_mode, delay, timeout)
|
79
65
|
finish_time = Time.now + timeout
|
80
66
|
one_time_mode = !daemon_mode
|
81
67
|
|
82
68
|
while true do
|
83
|
-
cleanup_disconnected_devices(filter
|
69
|
+
cleanup_disconnected_devices(filter)
|
84
70
|
|
85
71
|
if one_time_mode && Time.now > finish_time
|
86
72
|
raise "Connect loop timeout reached"
|
87
73
|
end
|
88
74
|
|
89
|
-
|
90
|
-
stf_devices =
|
91
|
-
stf_devices = stf_devices.by_filter(filter) if filter
|
92
|
-
stf_devices = stf_devices.select_healthy_for_connect(healthcheck) if healthcheck
|
75
|
+
stf_devices = DeviceList.new(DI[:stf].get_devices)
|
76
|
+
stf_devices = stf_devices.byFilter(filter) if filter
|
93
77
|
|
94
78
|
if all_flag
|
95
|
-
to_connect = stf_devices.size
|
79
|
+
to_connect = stf_devices.filterReadyToConnect.size
|
96
80
|
else
|
97
|
-
connected = devices &
|
81
|
+
connected = devices & stf_devices.asConnectUrlList
|
98
82
|
to_connect = wanted - connected.size
|
99
83
|
end
|
100
84
|
|
101
|
-
return if one_time_mode && to_connect
|
85
|
+
return if one_time_mode && to_connect == 0
|
102
86
|
|
103
87
|
if to_connect > 0
|
104
88
|
if stf_devices.empty?
|
@@ -116,41 +100,40 @@ module Stf
|
|
116
100
|
|
117
101
|
def count_connected_devices(filter)
|
118
102
|
stf_devices = DeviceList.new(DI[:stf].get_user_devices)
|
119
|
-
stf_devices = stf_devices.
|
120
|
-
connected = devices & stf_devices.
|
103
|
+
stf_devices = stf_devices.byFilter(filter) if filter
|
104
|
+
connected = devices & stf_devices.asConnectUrlList
|
121
105
|
connected.size
|
122
106
|
end
|
123
107
|
|
124
|
-
def cleanup_disconnected_devices(filter
|
125
|
-
to_disconnect = []
|
108
|
+
def cleanup_disconnected_devices(filter)
|
126
109
|
stf_devices = DeviceList.new(DI[:stf].get_user_devices)
|
110
|
+
stf_devices = stf_devices.byFilter(filter) if filter
|
111
|
+
connected = stf_devices.asConnectUrlList - devices
|
127
112
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
logger.info 'will be disconnected by filter: ' + disconnect_because_filter.join(',')
|
132
|
-
to_disconnect += disconnect_because_filter
|
133
|
-
end
|
113
|
+
connected.reject {|url| url.to_s.empty?}.each do |url|
|
114
|
+
logger.info 'Cleanup the device ' + url.to_s
|
115
|
+
DI[:stop_debug_session_interactor].execute(url)
|
134
116
|
end
|
117
|
+
end
|
135
118
|
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
to_disconnect += disconnect_by_health
|
141
|
-
end
|
142
|
-
end
|
119
|
+
def connect(filter, all_flag, wanted)
|
120
|
+
devices = DeviceList.new(DI[:stf].get_devices)
|
121
|
+
devices = devices.filterReadyToConnect
|
122
|
+
devices = devices.byFilter(filter) if filter
|
143
123
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
to_disconnect += dead_persons
|
124
|
+
if devices.empty?
|
125
|
+
logger.error 'There is no available devices with criteria ' + filter
|
126
|
+
return 0
|
148
127
|
end
|
149
128
|
|
150
|
-
|
151
|
-
|
152
|
-
DI[:
|
129
|
+
n = 0
|
130
|
+
devices.asArray.shuffle.each do |d|
|
131
|
+
n += 1 if DI[:start_one_debug_session_interactor].execute(d)
|
132
|
+
break if !all_flag && n >= wanted
|
153
133
|
end
|
134
|
+
|
135
|
+
n
|
154
136
|
end
|
137
|
+
|
155
138
|
end
|
156
139
|
end
|
@@ -3,6 +3,8 @@ require 'ADB'
|
|
3
3
|
|
4
4
|
require 'stf/client'
|
5
5
|
require 'stf/log/log'
|
6
|
+
require 'stf/errors'
|
7
|
+
require 'stf/model/session'
|
6
8
|
|
7
9
|
module Stf
|
8
10
|
class StartOneDebugSessionInteractor
|
@@ -38,26 +40,23 @@ module Stf
|
|
38
40
|
|
39
41
|
return true
|
40
42
|
|
41
|
-
rescue
|
43
|
+
rescue SignalException => e
|
44
|
+
raise e
|
45
|
+
rescue => e
|
42
46
|
begin
|
43
47
|
# we will try clean anyway
|
44
48
|
DI[:stf].remove_device serial
|
45
49
|
if test ?d, '/custom-metrics'
|
46
|
-
File.open('/custom-metrics/openstf_connect_fail', 'a') do
|
47
|
-
|
48
|
-
f.write("openstf_connect_fail,reason=\"#{escape(message)}\",serial=\"#{escape(serial)}\" count=1i #{Time.now.to_i}\n")
|
50
|
+
File.open('/custom-metrics/openstf_connect_fail', 'a') do
|
51
|
+
|f| f.write("openstf_connect_fail #{serial} #{Time.now.to_i}\n")
|
49
52
|
end
|
50
53
|
end
|
51
54
|
rescue
|
52
55
|
end
|
53
56
|
|
54
|
-
logger.error "Failed to connect to #{serial}: " + e
|
57
|
+
logger.error "Failed to connect to #{serial}: " + e.message
|
55
58
|
return false
|
56
59
|
end
|
57
60
|
end
|
58
|
-
|
59
|
-
def escape(s)
|
60
|
-
s.gsub(/["]/, '\"').gsub(/[ ]/, '\ ').gsub(/[=]/, '\=').gsub(/[,]/, '\,')
|
61
|
-
end
|
62
61
|
end
|
63
62
|
end
|
@@ -3,6 +3,7 @@ require 'ADB'
|
|
3
3
|
|
4
4
|
require 'stf/client'
|
5
5
|
require 'stf/log/log'
|
6
|
+
require 'stf/errors'
|
6
7
|
require 'stf/interactor/stop_debug_session_interactor'
|
7
8
|
require 'stf/model/device_list'
|
8
9
|
|
@@ -12,14 +13,19 @@ module Stf
|
|
12
13
|
include ADB
|
13
14
|
|
14
15
|
# byFilter:
|
16
|
+
# exceptFilter:
|
15
17
|
def execute(options = {})
|
16
18
|
DI[:demonizer].kill unless options[:nokill]
|
17
19
|
|
18
20
|
stf_devices = DeviceList.new(DI[:stf].get_user_devices)
|
19
21
|
|
20
|
-
stf_devices = stf_devices.
|
22
|
+
stf_devices = stf_devices.byFilter options[:byFilter] if options[:byFilter]
|
23
|
+
stf_devices = stf_devices.exceptFilter options[:exceptFilter] if options[:exceptFilter]
|
21
24
|
|
22
|
-
|
25
|
+
connected_devices = devices()
|
26
|
+
remote_devices = stf_devices.asConnectUrlList
|
27
|
+
|
28
|
+
pending_disconnect = connected_devices & remote_devices
|
23
29
|
|
24
30
|
pending_disconnect.each {|d| DI[:stop_debug_session_interactor].execute d}
|
25
31
|
end
|
data/lib/stf/model/device.rb
CHANGED
@@ -8,33 +8,7 @@ module Stf
|
|
8
8
|
getKeysNextLevel('', self)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
def healthy_for_connect?(pattern)
|
13
|
-
return true if pattern.nil?
|
14
|
-
health = healthy?(pattern)
|
15
|
-
ppp = pattern.split(',')
|
16
|
-
ppp.each do |p|
|
17
|
-
health &&= getValue('battery.temp').to_i < 30 if ['t', 'temp', 'temperature'].include? p
|
18
|
-
health &&= getValue('battery.level').to_f > 30.0 if ['b', 'batt', 'battery'].include? p
|
19
|
-
end
|
20
|
-
health
|
21
|
-
end
|
22
|
-
|
23
|
-
def healthy?(pattern)
|
24
|
-
return true if pattern.nil?
|
25
|
-
ppp = pattern.split(',')
|
26
|
-
health = true
|
27
|
-
ppp.each do |p|
|
28
|
-
health &&= getValue('battery.temp').to_i < 32 if ['t', 'temp', 'temperature'].include? p
|
29
|
-
health &&= getValue('battery.level').to_f > 20.0 if ['b', 'batt', 'battery'].include? p
|
30
|
-
health &&= getValue('network.connected') if ['n', 'net', 'network'].include? p
|
31
|
-
health &&= getValue('network.type') == 'VPN' if ['vpn'].include? p
|
32
|
-
health &&= getValue('network.type') == 'WIFI' if ['wifi'].include? p
|
33
|
-
end
|
34
|
-
health
|
35
|
-
end
|
36
|
-
|
37
|
-
def checkFilter?(filter)
|
11
|
+
def checkFilter(filter)
|
38
12
|
return true if filter.nil?
|
39
13
|
key, value = filter.split(':', 2)
|
40
14
|
getValue(key) == value
|
@@ -11,49 +11,20 @@ module Stf
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
filter ? select {|d| d.checkFilter
|
14
|
+
def byFilter(filter)
|
15
|
+
filter ? select {|d| d.checkFilter(filter)} : Array.new
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
filter ? reject {|d| d.checkFilter
|
18
|
+
def exceptFilter(filter)
|
19
|
+
filter ? reject {|d| d.checkFilter(filter)} : this
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
22
|
+
def filterReadyToConnect
|
23
|
+
select {|d| d.ready == true && d.present == true && d.usage.nil? }
|
24
24
|
end
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
pattern ? select { |d| d.healthy_for_connect?(pattern) } : this
|
29
|
-
end
|
30
|
-
|
31
|
-
def select_not_healthy(pattern)
|
32
|
-
pattern ? reject { |d| d.healthy?(pattern) } : []
|
33
|
-
end
|
34
|
-
|
35
|
-
def select_ready_to_connect
|
36
|
-
# https://github.com/openstf/stf/blob/93d9d7fe859bb7ca71669f375d841d94fa47d751/lib/wire/wire.proto#L170
|
37
|
-
# enum DeviceStatus {
|
38
|
-
# OFFLINE = 1;
|
39
|
-
# UNAUTHORIZED = 2;
|
40
|
-
# ONLINE = 3;
|
41
|
-
# CONNECTING = 4;
|
42
|
-
# AUTHORIZING = 5;
|
43
|
-
# }
|
44
|
-
#
|
45
|
-
# https://github.com/openstf/stf/blob/93d9d7fe859bb7ca71669f375d841d94fa47d751/res/app/components/stf/device/enhance-device/enhance-device-service.js
|
46
|
-
select {|d|
|
47
|
-
d.present == true &&
|
48
|
-
d.status == 3 &&
|
49
|
-
d.ready == true &&
|
50
|
-
d.using == false &&
|
51
|
-
d.owner.nil?
|
52
|
-
}
|
53
|
-
end
|
54
|
-
|
55
|
-
def as_connect_url_list
|
56
|
-
@devices.map {|d| d.remoteConnectUrl}.reject { |c| c.nil? || c.empty? }
|
26
|
+
def asConnectUrlList
|
27
|
+
@devices.map {|d| d.remoteConnectUrl}
|
57
28
|
end
|
58
29
|
|
59
30
|
def select
|
@@ -61,6 +32,7 @@ module Stf
|
|
61
32
|
end
|
62
33
|
|
63
34
|
def reject
|
35
|
+
# DeviceList.new(@devices.reject {|d| yield(d)})
|
64
36
|
DeviceList.new(@devices.select {|d| !yield(d)})
|
65
37
|
end
|
66
38
|
|
@@ -76,4 +48,4 @@ module Stf
|
|
76
48
|
@devices
|
77
49
|
end
|
78
50
|
end
|
79
|
-
end
|
51
|
+
end
|
data/lib/stf/version.rb
CHANGED
data/lib/stf/view/cli.rb
CHANGED
@@ -7,7 +7,7 @@ module Stf
|
|
7
7
|
|
8
8
|
extend self
|
9
9
|
|
10
|
-
program_desc
|
10
|
+
program_desc 'Smartphone Test Lab client'
|
11
11
|
|
12
12
|
desc 'Be verbose'
|
13
13
|
switch [:v, :verbose]
|
@@ -35,9 +35,6 @@ module Stf
|
|
35
35
|
Log::verbose(global_options[:verbose])
|
36
36
|
|
37
37
|
DI.init(global_options)
|
38
|
-
|
39
|
-
help_now!('Valid STF url is required, e.g. http(s)://openstf.local') if !DI[:uri_validator].validate(global_options[:url])
|
40
|
-
true
|
41
38
|
end
|
42
39
|
|
43
40
|
desc 'Search for a device available in STF and attach it to local adb server'
|
@@ -50,10 +47,6 @@ module Stf
|
|
50
47
|
c.flag [:min]
|
51
48
|
c.desc 'Filter key:value for devices'
|
52
49
|
c.flag [:f, :filter]
|
53
|
-
c.desc 'Force filter check for connected devices'
|
54
|
-
c.switch [:forcefilter, :ff]
|
55
|
-
c.desc 'Check selected health parameters, could be any of the: battery,temperature,network,vpn,wifi'
|
56
|
-
c.flag [:health]
|
57
50
|
c.desc 'Maximum session duration in seconds, 10800 (3h) by default'
|
58
51
|
c.flag [:session]
|
59
52
|
c.desc 'Maximum time to connect minimal quantity of devices in seconds, 120 (2m) by default'
|
@@ -68,7 +61,7 @@ module Stf
|
|
68
61
|
end
|
69
62
|
end
|
70
63
|
|
71
|
-
desc 'Show
|
64
|
+
desc 'Show avaliable keys for filtering'
|
72
65
|
command :keys do |c|
|
73
66
|
c.action {puts DI[:get_keys_interactor].execute}
|
74
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stf-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.0.
|
4
|
+
version: 0.3.0.rc2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anton Malinskiy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- lib/di.rb
|
200
200
|
- lib/stf.rb
|
201
201
|
- lib/stf/client.rb
|
202
|
+
- lib/stf/errors.rb
|
202
203
|
- lib/stf/interactor/get_keys_interactor.rb
|
203
204
|
- lib/stf/interactor/get_values_interactor.rb
|
204
205
|
- lib/stf/interactor/remove_all_user_devices_interactor.rb
|
@@ -209,8 +210,8 @@ files:
|
|
209
210
|
- lib/stf/log/log.rb
|
210
211
|
- lib/stf/model/device.rb
|
211
212
|
- lib/stf/model/device_list.rb
|
213
|
+
- lib/stf/model/session.rb
|
212
214
|
- lib/stf/system/demonizer.rb
|
213
|
-
- lib/stf/validate/uri_validator.rb
|
214
215
|
- lib/stf/version.rb
|
215
216
|
- lib/stf/view/cli.rb
|
216
217
|
- stf-client.gemspec
|
@@ -234,7 +235,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
234
235
|
version: 1.3.1
|
235
236
|
requirements: []
|
236
237
|
rubyforge_project:
|
237
|
-
rubygems_version: 2.
|
238
|
+
rubygems_version: 2.6.13
|
238
239
|
signing_key:
|
239
240
|
specification_version: 4
|
240
241
|
summary: Request devices from Smartphone Test Farm for adb connection
|