tes-request 0.2 → 0.3
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/README.md +26 -10
- data/bin/tes-client +17 -0
- data/lib/tes/request/client.rb +110 -2
- data/lib/tes/request/version.rb +1 -1
- data/tes-request.gemspec +4 -3
- metadata +22 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f2801298fca82cc8a1001b03f767bc40762bb584
|
4
|
+
data.tar.gz: d03c89d8663d1e995ba8874a6f5a47decb86e7b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a804cb2eec661e57d60fb074ee95e7d4d070b1f4aa8df3992e6497fa5fa7b4f101cef785ce195d9e9e54b6de1bd9304231068f9ec968e542fca84fe7c356e20
|
7
|
+
data.tar.gz: af30855c4cc23fd18318eb78bd3dab35b171bd216cb08cfe5cba2937180fef4aa927e2b977d59a0f39764b6df96f91786cb00c99467f8858af835534e54cf0ba
|
data/.travis.yml
CHANGED
@@ -14,8 +14,7 @@ script:
|
|
14
14
|
- bundle exec rspec
|
15
15
|
deploy:
|
16
16
|
provider: rubygems
|
17
|
-
api-key:
|
18
|
-
secure: VILjurTJb9jwpQE+RVQ93DZjqR2nVrjkuh8TAIEiaKjGvLdFqWN5QBQ8BRRU+7nOLowyp0YB+/TYRd0oNslz+BZDEgisLWmzjvDXdJQtZuk/2TnslumTctF3uz9ankwESaBrembgC/BPye/Xpio8oaXx9huOGYqIKD8cKX1U8/lFZKCfRIHCYo+7iETBdifBp6e3jj3ABGrCeurcvC0GUPlhcnYrYTjvXsmLVCxQCWyQZ7KfW/9dnqI2ssfeTLgg6VGO5uCR+dvKaiZis9YKICfrmaKSsZBQrHXr49b7jnizTkAVbg/JG9LG/Y+Xs8LeF/8Rx270EEP0TKnwpzWzzOn2yV6D7TeFnzHq0xn+0xoehtcL0jNv7rAGgCzkS4CrR0fWdAITZylhHYBVx4aTLhJ3SEVMxexuyych6JhSWVDvq7ouYIyBKhDtHKTpTQjznsqAGVAxWXjRlbd/GOzwvwqB32pgnqfHQX7zMMOGQk0t4nHMVIieSfVetOXXUAERjiMAajWJTwI0/exeodzD0vVF9kfpOB1RLtQgSYxOyD2nu8TSloxiF5ZLzypQw1wRg0ctzpOUuz/tgIHtyK9gJtY1XYV4mgXlEdtteM6GdYoLj8AKjaOpi9evEM+QnGYsI4xoLq4P6XgDjyBpzFoUkBO8E7u0nPQRsB86yqLINLI=
|
17
|
+
api-key: $RUBYGEMS_API_KEY
|
19
18
|
on:
|
20
19
|
tags: true
|
21
20
|
rvm: 2.4.1
|
data/README.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Tes::Request
|
2
2
|
|
3
|
-
TES(Test Env Service) request profile struct and manager lib
|
4
|
-
|
5
3
|
[](https://travis-ci.org/wuhuizuo/tes-request)
|
4
|
+
[](https://rubygems.org/gems/tes-request)
|
5
|
+
|
6
|
+
TES(Test Env Service) request profile struct, manager lib and request tools
|
6
7
|
|
7
8
|
## Installation
|
8
9
|
|
@@ -18,9 +19,13 @@ And then execute:
|
|
18
19
|
Or install it yourself as:
|
19
20
|
|
20
21
|
$ gem install tes-request
|
22
|
+
# check bins:
|
23
|
+
$ tes-ci-slicer
|
24
|
+
$ tes-client
|
21
25
|
|
22
26
|
## Usage
|
23
27
|
|
28
|
+
### tes-ci-slicer
|
24
29
|
Given you project root path: `/project/root/path`, and there has file `.ci.yml`, file contents as follow:
|
25
30
|
|
26
31
|
```yml
|
@@ -54,24 +59,35 @@ end
|
|
54
59
|
|
55
60
|
Then you need to slice all spec script to several paralleled jobs.
|
56
61
|
|
57
|
-
**Step:**
|
58
|
-
|
59
|
-
1. install this gem
|
60
|
-
2. run cmds like:
|
62
|
+
**Step:** run cmds like
|
61
63
|
|
62
64
|
```bash
|
63
65
|
tes-ci-slicer properties apps/test_project func_test 16 apps/test_project/res_attr_add_map.json
|
64
66
|
```
|
65
67
|
|
66
|
-
|
68
|
+
### tes-client
|
67
69
|
|
68
|
-
|
70
|
+
```bash
|
71
|
+
# run tes-client without args to sees help usage:
|
72
|
+
$ tes-client
|
73
|
+
|
74
|
+
# Usage:
|
75
|
+
# % /usr/local/bin/tes-client {TesWebUrl} {User} request_res {ResourceId} [1|0] # Request Specified Resource
|
76
|
+
# % /usr/local/bin/tes-client {TesWebUrl} {User} release_res {ResourceId} # Release Specified Resource
|
77
|
+
# % /usr/local/bin/tes-client {TesWebUrl} {User} request_pool {PoolAskFile} {SaveFile} [TimeoutSeconds] # Request Env Pool
|
78
|
+
# % /usr/local/bin/tes-client {TesWebUrl} {User} release_pool [PoolFile] # Release Env Pool
|
79
|
+
```
|
80
|
+
|
81
|
+
## Development
|
69
82
|
|
70
|
-
|
83
|
+
- After checking out the repo, run `bundle` to install dependencies. Then, run `rake spec` to run the tests.
|
84
|
+
- To install this gem onto your local machine, run `bundle exec rake install`.
|
85
|
+
- To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
71
86
|
|
72
87
|
## Contributing
|
73
88
|
|
74
|
-
Bug reports and pull requests are welcome on GitHub at
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wuhuizuo/tes-request.
|
90
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
75
91
|
|
76
92
|
## License
|
77
93
|
|
data/bin/tes-client
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'tes/request/client'
|
5
|
+
|
6
|
+
if ARGV.size < 3
|
7
|
+
Tes::Request::ClientBin.exit_usage($0, 2)
|
8
|
+
else
|
9
|
+
tes_web_url = ARGV.shift
|
10
|
+
tes_op_user = ARGV.shift
|
11
|
+
tes_op_type = ARGV.shift
|
12
|
+
tes_op_args = ARGV
|
13
|
+
|
14
|
+
Tes::Request::ClientBin.
|
15
|
+
new(tes_web_url, tes_op_user).
|
16
|
+
run(tes_op_type, tes_op_args, $0)
|
17
|
+
end
|
data/lib/tes/request/client.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'httpclient'
|
3
|
+
require 'timeout'
|
2
4
|
|
3
5
|
module Tes
|
4
6
|
module Request
|
@@ -37,8 +39,11 @@ module Tes
|
|
37
39
|
ret
|
38
40
|
end
|
39
41
|
|
40
|
-
|
41
|
-
|
42
|
+
# @param [String] id resource id
|
43
|
+
# @param [String] user lock/using username
|
44
|
+
# @param [1,0] lock need lock? `false` == shared using
|
45
|
+
def request_res(id, user, lock=1)
|
46
|
+
res = @driver.post("/res/#{id}/lock", body: {user: user, lock: lock})
|
42
47
|
parse_res res
|
43
48
|
end
|
44
49
|
|
@@ -68,5 +73,108 @@ module Tes
|
|
68
73
|
end
|
69
74
|
end
|
70
75
|
end
|
76
|
+
|
77
|
+
class ClientBin
|
78
|
+
def self.exit_usage(program, exit_code=2)
|
79
|
+
puts <<EOF
|
80
|
+
Usage:
|
81
|
+
% #{program} {TesWebUrl} {User} request_res {ResourceId} [1|0] # Request Specified Resource
|
82
|
+
% #{program} {TesWebUrl} {User} release_res {ResourceId} # Release Specified Resource
|
83
|
+
% #{program} {TesWebUrl} {User} request_pool {PoolAskFile} {SaveFile} [TimeoutSeconds] # Request Env Pool
|
84
|
+
% #{program} {TesWebUrl} {User} release_pool [PoolFile] # Release Env Pool
|
85
|
+
EOF
|
86
|
+
exit exit_code
|
87
|
+
end
|
88
|
+
|
89
|
+
def initialize(tes_url, user)
|
90
|
+
driver = HTTPClient.new(base_url: tes_url)
|
91
|
+
driver.ssl_config.verify_mode= OpenSSL::SSL::VERIFY_NONE
|
92
|
+
@client = Client.new(driver)
|
93
|
+
@user = user
|
94
|
+
end
|
95
|
+
|
96
|
+
# Cli runner method
|
97
|
+
# @param [String] op_type
|
98
|
+
# @param [Array<String>] op_args
|
99
|
+
def run(op_type, op_args, program = __FILE__)
|
100
|
+
assert_args(op_type, op_args) ? send(op_type, *op_args) : self.exit_usage(program, 2)
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def assert_args(op_type, op_args)
|
106
|
+
case op_type
|
107
|
+
when 'request_res'
|
108
|
+
op_args.size.between?(1, 2)
|
109
|
+
when 'release_res'
|
110
|
+
op_args.size == 1
|
111
|
+
when 'request_pool'
|
112
|
+
op_args.size.between?(2, 3)
|
113
|
+
when 'release_pool'
|
114
|
+
op_args.size.between?(0, 1)
|
115
|
+
else
|
116
|
+
false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def request_res(res_id, lock=0)
|
121
|
+
ret = @client.request_res(res_id, @user, lock)
|
122
|
+
|
123
|
+
msg_suffix = "Request resource:(id: #{res_id}, user: #{@user}, lock: #{lock})."
|
124
|
+
ret[:success] ? puts("[ OK ] #{msg_suffix}") : warn("[Fail] #{msg_suffix}")
|
125
|
+
|
126
|
+
ret[:success]
|
127
|
+
end
|
128
|
+
|
129
|
+
def release_res(res_id)
|
130
|
+
ret = @client.release_res(res_id, @user)
|
131
|
+
|
132
|
+
msg_suffix = "Release resource:(id: #{res_id}, user: #{@user})."
|
133
|
+
ret[:success] ? puts("[ OK ] #{msg_suffix}") : warn("[Fail] #{msg_suffix}")
|
134
|
+
|
135
|
+
ret[:success]
|
136
|
+
end
|
137
|
+
|
138
|
+
def release_pool(saved_env_file=nil)
|
139
|
+
if saved_env_file and File.exists?(saved_env_file)
|
140
|
+
env_pool_info = YAML.load_file(saved_env_file)
|
141
|
+
locks = env_pool_info[:lockes]
|
142
|
+
locks.each { |lock| @client.release_res(lock, @user) } if locks
|
143
|
+
puts "[Info] Release env done(user: #{@user}, file: #{saved_env_file})."
|
144
|
+
else
|
145
|
+
@client.release_all_res(@user)
|
146
|
+
puts "[Info] Release env done(user: #{@user})."
|
147
|
+
end
|
148
|
+
|
149
|
+
true
|
150
|
+
end
|
151
|
+
|
152
|
+
# request env pool
|
153
|
+
def request_pool(profile_file, save_file, timeout_secs=0)
|
154
|
+
File.exists?(profile_file) || raise(ArgumentError, "[ ER ] File not found:#{profile_file}")
|
155
|
+
|
156
|
+
asks = File.readlines(profile_file).map!(&:strip).compact
|
157
|
+
|
158
|
+
Timeout.timeout(timeout_secs && timeout_secs.to_i) do
|
159
|
+
print '[Info] Request env...'
|
160
|
+
|
161
|
+
ret = {}
|
162
|
+
until ret[:success]
|
163
|
+
print '.'
|
164
|
+
ret = @client.request_env(@user, asks)
|
165
|
+
sleep 5 unless ret[:success]
|
166
|
+
end
|
167
|
+
|
168
|
+
# request successfully
|
169
|
+
puts 'successfully!'
|
170
|
+
File.open(save_file, 'w') do |f|
|
171
|
+
f.write ret[:data].to_yaml
|
172
|
+
puts '[ OK ] Request env done, saved in: ' + save_file
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
true
|
177
|
+
end
|
178
|
+
end
|
71
179
|
end
|
72
180
|
end
|
data/lib/tes/request/version.rb
CHANGED
data/tes-request.gemspec
CHANGED
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['wuhuizuo']
|
10
10
|
spec.email = ['wuhuizuo@126.com']
|
11
11
|
|
12
|
-
spec.summary = %q{Request
|
13
|
-
spec.description = %q{
|
14
|
-
spec.homepage = '
|
12
|
+
spec.summary = %q{Request libs and bins for TES(Test Env Service)}
|
13
|
+
spec.description = %q{Provide Tes-Client, Tes-Provider to use public Logic and data struct}
|
14
|
+
spec.homepage = 'https://github.com/wuhuizuo/tes-request'
|
15
15
|
spec.license = 'MIT'
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.require_paths = ['lib']
|
32
32
|
|
33
33
|
spec.add_runtime_dependency 'java-properties', '~> 0.2'
|
34
|
+
spec.add_runtime_dependency 'httpclient', '~> 2.8.3'
|
34
35
|
spec.add_development_dependency 'rake', '~> 12.0'
|
35
36
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
36
37
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tes-request
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wuhuizuo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: java-properties
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: httpclient
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.8.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.8.3
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,11 +80,12 @@ dependencies:
|
|
66
80
|
- - "~>"
|
67
81
|
- !ruby/object:Gem::Version
|
68
82
|
version: '1.13'
|
69
|
-
description:
|
83
|
+
description: Provide Tes-Client, Tes-Provider to use public Logic and data struct
|
70
84
|
email:
|
71
85
|
- wuhuizuo@126.com
|
72
86
|
executables:
|
73
87
|
- tes-ci-slicer
|
88
|
+
- tes-client
|
74
89
|
extensions: []
|
75
90
|
extra_rdoc_files: []
|
76
91
|
files:
|
@@ -83,6 +98,7 @@ files:
|
|
83
98
|
- README.md
|
84
99
|
- Rakefile
|
85
100
|
- bin/tes-ci-slicer
|
101
|
+
- bin/tes-client
|
86
102
|
- lib/hash.rb
|
87
103
|
- lib/tes/request.rb
|
88
104
|
- lib/tes/request/ask.rb
|
@@ -96,7 +112,7 @@ files:
|
|
96
112
|
- lib/tes/request/rspec/profile_parser.rb
|
97
113
|
- lib/tes/request/version.rb
|
98
114
|
- tes-request.gemspec
|
99
|
-
homepage:
|
115
|
+
homepage: https://github.com/wuhuizuo/tes-request
|
100
116
|
licenses:
|
101
117
|
- MIT
|
102
118
|
metadata:
|
@@ -117,9 +133,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
117
133
|
version: '0'
|
118
134
|
requirements: []
|
119
135
|
rubyforge_project:
|
120
|
-
rubygems_version: 2.5
|
136
|
+
rubygems_version: 2.4.5
|
121
137
|
signing_key:
|
122
138
|
specification_version: 4
|
123
|
-
summary: Request
|
139
|
+
summary: Request libs and bins for TES(Test Env Service)
|
124
140
|
test_files: []
|
125
|
-
has_rdoc:
|