vscripts 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +13 -5
  2. data/.travis.yml +8 -1
  3. data/CHANGELOG.md +23 -0
  4. data/README.md +3 -1
  5. data/Rakefile +1 -3
  6. data/VERSION +1 -1
  7. data/lib/vscripts.rb +1 -1
  8. data/lib/vscripts/aws.rb +5 -0
  9. data/lib/vscripts/aws/ec2.rb +11 -16
  10. data/lib/vscripts/command_line.rb +3 -3
  11. data/lib/vscripts/{command.rb → commands.rb} +1 -1
  12. data/lib/vscripts/commands/identify.rb +9 -19
  13. data/lib/vscripts/commands/tags2facts.rb +7 -25
  14. data/lib/vscripts/util.rb +12 -0
  15. data/lib/vscripts/util/local_system.rb +1 -29
  16. data/spec/aws_spec_helper.rb +10 -0
  17. data/spec/spec_helper.rb +27 -2
  18. data/spec/unit/vscripts/aws/ec2_spec.rb +98 -0
  19. data/spec/unit/vscripts/aws/metadata_spec.rb +62 -0
  20. data/spec/{vscripts → unit/vscripts}/aws_spec.rb +3 -1
  21. data/spec/unit/vscripts/command_line_spec.rb +43 -0
  22. data/spec/unit/vscripts/commands/identify_spec.rb +178 -0
  23. data/spec/unit/vscripts/commands/tags2facts_spec.rb +52 -0
  24. data/spec/unit/vscripts/commands_spec.rb +10 -0
  25. data/spec/unit/vscripts/util/local_system_spec.rb +82 -0
  26. data/spec/{vscripts → unit/vscripts}/version_spec.rb +1 -0
  27. data/spec/unit/vscripts_spec.rb +27 -0
  28. data/tasks/deploy.rake +6 -1
  29. data/tasks/lint.rake +1 -1
  30. data/vscripts.gemspec +3 -1
  31. metadata +86 -56
  32. data/.rspec +0 -2
  33. data/spec/vscripts/aws/ec2_spec.rb +0 -90
  34. data/spec/vscripts/aws/metadata_spec.rb +0 -48
  35. data/spec/vscripts/command_line_spec.rb +0 -34
  36. data/spec/vscripts/command_spec.rb +0 -9
  37. data/spec/vscripts/commands/identify_spec.rb +0 -111
  38. data/spec/vscripts/commands/tags2facts_spec.rb +0 -35
  39. data/spec/vscripts/util/local_system_spec.rb +0 -80
  40. data/spec/vscripts_spec.rb +0 -4
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --colour
2
- --format documentation
@@ -1,90 +0,0 @@
1
- require 'spec_helper'
2
- require 'vscripts/aws/ec2'
3
- require 'ostruct'
4
-
5
- describe VScripts::AWS::EC2 do
6
- before :each do
7
- ::AWS.config({
8
- :access_key_id => '1234',
9
- :secret_access_key => '5678',
10
- :region => 'us-east-1',
11
- :logger => nil,
12
- :stub_requests => true
13
- })
14
-
15
- @tags = {'Name' => 'test'}
16
-
17
- @inst1 = OpenStruct.new(id: '1111', status: :running)
18
- @inst2 = OpenStruct.new(id: '2222', status: :running, tags: @tags)
19
- @inst3 = OpenStruct.new(id: '3333', status: :terminated)
20
-
21
- @ec2 = VScripts::AWS::EC2
22
- @ec2.any_instance.stub(:check_instance) { true }
23
- @ec2.any_instance.stub(:instance_id) { @inst1.id }
24
- @ec2.any_instance.stub(:region) { 'us-east-1' }
25
- end
26
-
27
- describe '#instance' do
28
- it 'returns AWS::EC2' do
29
- expect(subject.ec2).to be_an_instance_of ::AWS::EC2
30
- end
31
- end
32
-
33
- describe '#new' do
34
- it 'returns AWS::EC2::Instance' do
35
- expect(subject.instance).to be_an_instance_of ::AWS::EC2::Instance
36
- expect(subject.instance.id).to eq(@inst1.id)
37
- end
38
- end
39
-
40
- describe '#all_tags' do
41
- it 'returns AWS::EC2::ResourceTagCollection' do
42
- expect(subject.all_tags)
43
- .to be_an_instance_of ::AWS::EC2::ResourceTagCollection
44
- end
45
- end
46
-
47
- describe '#tag' do
48
- it 'returns the tag value' do
49
- subject.stub_chain(:instance, :tags) {@tags}
50
- expect(subject.tag('Name'))
51
- .to eq('test')
52
- end
53
- end
54
-
55
- describe '#tags_without' do
56
- it 'returns a Hash' do
57
- expect(subject.tags_without)
58
- .to be_an_instance_of ::AWS::EC2::ResourceTagCollection
59
- end
60
- end
61
-
62
- describe '#name' do
63
- it 'returns Hash value' do
64
- subject.stub(:all_tags_hash) {@tags}
65
- expect(subject.name).to eq(@tags['Name'])
66
- end
67
- end
68
-
69
- describe '#named_instances' do
70
- it 'returns AWS::EC2::InstanceCollection' do
71
- expect(subject.named_instances)
72
- .to be_an_instance_of ::AWS::EC2::InstanceCollection
73
- end
74
- end
75
-
76
- describe '#functional_instances' do
77
- it 'returns an Array' do
78
- subject.stub(:named_instances) { [@inst1, @inst2, @inst3] }
79
- expect(subject.functional_instances).to be_an Array
80
- expect(subject.functional_instances).to include(@inst1, @inst2)
81
- end
82
- end
83
-
84
- describe '#similar_instances' do
85
- it 'returns an Array' do
86
- subject.stub(:functional_instances) { [@inst1, @inst2] }
87
- expect(subject.similar_instances).to include(@tags['Name'])
88
- end
89
- end
90
- end
@@ -1,48 +0,0 @@
1
- require 'spec_helper'
2
- require 'vscripts/aws/metadata'
3
-
4
- describe VScripts::AWS::Metadata do
5
- before(:each) do
6
- @dummy = DummyClass.new
7
- @dummy.extend VScripts::AWS::Metadata
8
- @dummy.stub_chain(:open, :read).and_return('Remote server response')
9
- end
10
-
11
- describe '#metadata_url' do
12
- it 'returns metadata url string' do
13
- expect(@dummy.metadata_url).to be_a String
14
- end
15
- end
16
-
17
- describe '#zone' do
18
- it 'returns zone string' do
19
- expect(@dummy.zone).to eq('Remote server response')
20
- end
21
- end
22
-
23
- describe '#region' do
24
- it 'returns region string' do
25
- @dummy.stub(:zone).and_return('us-test-1a')
26
- expect(@dummy.region).to eq('us-test-1')
27
- end
28
- end
29
-
30
- describe '#instance_id' do
31
- it 'returns instance id string' do
32
- expect(@dummy.instance_id).to eq('Remote server response')
33
- end
34
- end
35
-
36
- describe '#public_hostname' do
37
- it 'returns public hostname string' do
38
- expect(@dummy.public_hostname).to eq('Remote server response')
39
- end
40
- end
41
-
42
- describe '#ec2_instance?' do
43
- it 'returns true' do
44
- Net::HTTP.stub(:get_response).and_return(true)
45
- expect(@dummy.ec2_instance?).to be_true
46
- end
47
- end
48
- end
@@ -1,34 +0,0 @@
1
- require 'vscripts/command_line'
2
-
3
- describe VScripts::CommandLine do
4
- before :each do
5
- @cmd = VScripts::Command.list.first.to_s
6
- @cli = VScripts::CommandLine.new([@cmd, 'extra_args'])
7
- end
8
-
9
- describe '#new' do
10
- it 'returns the command line arguments' do
11
- expect(@cli).to be_an_instance_of VScripts::CommandLine
12
- end
13
- end
14
-
15
- describe '#global' do
16
- it 'returns the global options as a Hash' do
17
- expect(@cli.global).to be_an_instance_of Hash
18
- end
19
- end
20
-
21
- describe '#command' do
22
- it 'returns the command name' do
23
- expect(@cli.command).to be_a Symbol
24
- expect(@cli.command).to eql @cmd.capitalize.to_sym
25
- end
26
- end
27
-
28
- describe '#extra' do
29
- it 'returns the rest of the arguments as an Array' do
30
- expect(@cli.arguments).to be_an_instance_of Array
31
- expect(@cli.arguments).to eql ['extra_args']
32
- end
33
- end
34
- end
@@ -1,9 +0,0 @@
1
- require 'vscripts/command'
2
-
3
- describe VScripts::Command do
4
- describe '#list' do
5
- it 'returns a list of available commands' do
6
- expect(VScripts::Command.list).to be_an_instance_of Array
7
- end
8
- end
9
- end
@@ -1,111 +0,0 @@
1
- require 'spec_helper'
2
- require 'vscripts/commands/identify'
3
-
4
- describe VScripts::Commands::Identify do
5
- before :each do
6
- @identify = VScripts::Commands::Identify.new
7
- @identify.stub_chain(:ec2, :tag).with('Group') {'TestGroup'}
8
- @identify.stub_chain(:ec2, :tag).with('Role') {'TestRole'}
9
- @identify.stub_chain(:ec2, :similar_instances) {[
10
- 'TestGroup-TestRole-1.'
11
- ]}
12
- end
13
-
14
- describe '#new' do
15
- context 'when theme is not passed' do
16
- it 'returns the default theme' do
17
- expect(@identify.theme).to eq('Group-Role-#')
18
- end
19
- end
20
- context 'when theme is passed' do
21
- it 'returns the theme' do
22
- @identify = VScripts::Commands::Identify.new(['--ec2-tag-theme=test'])
23
- expect(@identify.theme).to eq('test')
24
- end
25
- end
26
- context 'when host is not passed' do
27
- it 'host is nil' do
28
- expect(@identify.host).to be_nil
29
- end
30
- end
31
- context 'when host is passed' do
32
- it 'returns the host' do
33
- @identify = VScripts::Commands::Identify.new(['--host=test'])
34
- expect(@identify.host).to eq('test')
35
- end
36
- end
37
- context 'when domain is not passed' do
38
- it 'domain is nil' do
39
- expect(@identify.domain).to be_nil
40
- end
41
- end
42
- context 'when domain is passed' do
43
- it 'returns the domain' do
44
- @identify = VScripts::Commands::Identify.new(['--domain=test'])
45
- expect(@identify.domain).to eq('test')
46
- end
47
- end
48
- end
49
-
50
- describe '#theme_elements' do
51
- it 'returns an array' do
52
- expect(@identify.theme_elements).to eq(['Group', 'Role', '#'])
53
- end
54
- end
55
-
56
- describe '#map2tags' do
57
- it 'returns an array' do
58
- expect(@identify.map2tags).to eq(['TestGroup', 'TestRole', '#'])
59
- end
60
- end
61
-
62
- describe '#themed_host_name' do
63
- it 'returns a string' do
64
- expect(@identify.themed_host_name).to eq('TestGroup-TestRole-#')
65
- end
66
- end
67
-
68
- describe '#incremented_hostname' do
69
- it 'returns a string' do
70
- expect(@identify.incremented_hostname).to eq('TestGroup-TestRole-2')
71
- end
72
- end
73
-
74
- describe '#new_hostname' do
75
- context 'when host is not passed' do
76
- it 'hostname is incremented' do
77
- expect(@identify.new_hostname).to eq('TestGroup-TestRole-2')
78
- end
79
- end
80
- context 'when host is passed' do
81
- it 'returns a string' do
82
- @identify = VScripts::Commands::Identify.new(['--host=test'])
83
- expect(@identify.new_hostname).to eq('test')
84
- end
85
- end
86
- end
87
-
88
- describe '#new_domain' do
89
- context 'when domain is not passed' do
90
- context 'when tag is not present' do
91
- it 'returns a String' do
92
- @identify.stub_chain(:ec2, :tag).with('Domain') {nil}
93
- @identify.stub(:local_domain_name) {'local'}
94
- expect(@identify.new_domain).to eq('local')
95
- end
96
- end
97
- context 'when tag is present' do
98
- it 'returns a String' do
99
- @identify.stub_chain(:ec2, :tag).with('Domain') {'Test'}
100
- expect(@identify.new_domain).to eq('Test')
101
- end
102
- end
103
- end
104
- context 'when domain is passed' do
105
- it 'returns a string' do
106
- @identify = VScripts::Commands::Identify.new(['--domain=test'])
107
- expect(@identify.new_domain).to eq('test')
108
- end
109
- end
110
- end
111
- end
@@ -1,35 +0,0 @@
1
- require 'vscripts/commands/tags2facts'
2
-
3
- describe VScripts::Commands::Tags2facts do
4
-
5
- before :each do
6
- VScripts::AWS::EC2.any_instance.stub(:region) { 'us-east-1' }
7
- @tags2facts = VScripts::Commands::Tags2facts.new(['extra_args'])
8
- end
9
-
10
- describe '#new' do
11
- it 'returns cli arguments and loads EC2 SDK' do
12
- expect(@tags2facts.cli).to be_a Hash
13
- expect(@tags2facts.ec2).to be_an_instance_of VScripts::AWS::EC2
14
- end
15
- end
16
-
17
- describe '#parser' do
18
- it 'returns parser' do
19
- expect(@tags2facts.parser).to be_an_instance_of Trollop::Parser
20
- end
21
- end
22
-
23
- describe '#exclude_list' do
24
- it 'returns exclude list' do
25
- expect(@tags2facts.exclude_list).to eq(['Name', 'Domain'])
26
- end
27
- end
28
-
29
- describe '#tags_json' do
30
- it 'returns JSON formatted string' do
31
- @tags2facts.stub(:filtered_tags) {{ key: 'value' }}
32
- expect(@tags2facts.tags_json).to eq("{\n \"key\": \"value\"\n}")
33
- end
34
- end
35
- end
@@ -1,80 +0,0 @@
1
- require 'spec_helper'
2
- require 'tempfile'
3
- require 'vscripts/util/local_system'
4
-
5
- describe VScripts::Util::LocalSystem do
6
- before(:all) do
7
- @dummy = DummyClass.new
8
- @dummy.extend VScripts::Util::LocalSystem
9
- end
10
-
11
- describe '#hosts_path' do
12
- it 'returns the path to hosts file' do
13
- expect(@dummy.hosts_path).to be_a String
14
- end
15
- end
16
- describe '#hostname_path' do
17
- it 'returns the path to the hostname file' do
18
- expect(@dummy.hostname_path).to be_a String
19
- end
20
- end
21
- describe '#local_fqdn' do
22
- it 'returns the local FQDN' do
23
- expect(@dummy.local_fqdn).to be_a String
24
- end
25
- end
26
- describe '#local_host_name' do
27
- it 'returns the local host name' do
28
- expect(@dummy.local_host_name).to be_a String
29
- end
30
- end
31
- describe '#local_domain_name' do
32
- it 'returns the local domain name' do
33
- expect(@dummy.local_domain_name).to be_a String
34
- end
35
- end
36
- describe '#ensure_file_dir' do
37
- it 'create a directory for the specified files' do
38
- test_dir = Dir::Tmpname.make_tmpname '/tmp/vscripts', nil
39
- test_file = 'test_file'
40
- @dummy.ensure_file_dir("#{test_dir}/#{test_file}")
41
- expect(Dir.exists?(test_dir)).to be_true
42
- `rm -r #{test_dir}`
43
- end
44
- end
45
- describe '#write_file' do
46
- it 'should write to a file' do
47
- test_file = Dir::Tmpname.make_tmpname '/tmp/vscripts', nil
48
- @dummy.write_file(test_file, 'test')
49
- expect(IO.read(test_file)).to eq('test')
50
- `rm #{test_file}`
51
- end
52
- end
53
- describe '#ensure_file_content' do
54
- it 'should ensure content of file' do
55
- test_dir = Dir::Tmpname.make_tmpname '/tmp/vscripts', nil
56
- test_file = 'test_file'
57
- test = "#{test_dir}/#{test_file}"
58
- @dummy.ensure_file_content(test, 'test')
59
- expect(IO.read(test)).to eq('test')
60
- `rm -r #{test_dir}`
61
- end
62
- end
63
- describe '#checks' do
64
- it 'returns an array of checks' do
65
- expect(@dummy.checks).to be_a Hash
66
- end
67
- end
68
- describe '#process_checks' do
69
- it 'should execute system command and return exit code' do
70
- @dummy.stub(:checks) {{'test command' => 'exit 5'}}
71
- expect(@dummy.process_checks).to eq({"test command"=>5})
72
- end
73
- end
74
- describe '#status_codes' do
75
- it 'should return an Array of exit codes' do
76
- @dummy.stub(:checks) {{'test command' => 'exit 5'}}
77
- expect(@dummy.status_codes).to eq([5])
78
- end
79
- end
80
- end
@@ -1,4 +0,0 @@
1
- require 'vscripts'
2
-
3
- describe VScripts do
4
- end