File: vm_configuration_spec.rb

package info (click to toggle)
ruby-fission 0.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 624 kB
  • sloc: ruby: 4,664; makefile: 10
file content (132 lines) | stat: -rw-r--r-- 5,288 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
require 'spec_helper'

describe Fission::VMConfiguration do
  before do
    @vm = Fission::VM.new 'foo'
    @conf_file_response_mock = double('conf_file_response')
    @conf_file_response_mock.stub_as_successful @conf_file_path
  end

  describe 'config_data' do
    before do
      @vm.stub(:exists?).and_return(true)
      @vm_config = Fission::VMConfiguration.new @vm
      @vm.stub(:conf_file).and_return(@conf_file_response_mock)
    end

    it "should return an unsuccessful response if the vm doesn't exist" do
      @vm.stub(:exists?).and_return(false)
      @vm_config.config_data.should be_an_unsuccessful_response 'VM does not exist'
    end

    it 'should return an unsuccessful response if unable to figure out the conf file' do
      @conf_file_response_mock.stub_as_unsuccessful
      @vm_config.config_data.should be_an_unsuccessful_response
    end

    context 'when the vm exists and the conf file can be found' do
      before do
        @conf_file_io = StringIO.new
        vmx_content = '.encoding = "UTF-8"
config.version = "8"
virtualHW.version = "7"
scsi0.present = "TRUE"
scsi0.virtualDev = "lsilogic"
memsize = "384"
scsi0:0.present = "TRUE"
scsi0:0.fileName = "u10_04-000001.vmdk"
ethernet0.present = "TRUE"
ethernet0.connectionType = "nat"
ethernet0.wakeOnPcktRcv = "FALSE"
ethernet0.addressType = "generated"
ethernet0.linkStatePropagation.enable = "TRUE"
ehci.present = "TRUE"
pciBridge4.virtualDev = "pcieRootPort"
pciBridge4.functions = "8"
vmci0.present = "TRUE"
roamingVM.exitBehavior = "go"
tools.syncTime = "TRUE"
displayName = "u10_04"
guestOS = "ubuntu"
nvram = "u10_04.nvram"
virtualHW.productCompatibility = "hosted"
tools.upgrade.policy = "upgradeAtPowerCycle"
extendedConfigFile = "u10_04.vmxf"
serial0.present = "FALSE"
usb.present = "FALSE"
checkpoint.vmState = "u10_04.vmss"
ethernet0.generatedAddress = "00:0c:29:c4:94:22"
uuid.location = "56 4d 4b e9 1a bb 22 3a-b0 91 06 4e b4 c4 94 22"
uuid.bios = "56 4d 4b e9 1a bb 22 3a-b0 91 06 4e b4 c4 94 22"
cleanShutdown = "TRUE"
scsi0:0.redo = ""
scsi0.pciSlotNumber = "16"
ethernet0.pciSlotNumber = "32"
ethernet0.generatedAddressOffset = "0"
vmci0.id = "-1262185438"
tools.remindInstall = "TRUE"'
        @conf_file_io.string = vmx_content
        File.should_receive(:readlines).with(@conf_file_path).
                                         and_return(@conf_file_io.string.split(/$/))
      end

      it 'should return a successful response' do
        @vm_config.config_data.should be_a_successful_response
      end

      it 'should return the data as a hash like object' do
        config = @vm_config.config_data
        config.data.should respond_to :keys
        config.data.should respond_to :values
        config.data.should respond_to :each_pair
        config.data.should respond_to :[]
      end

      it 'should return accurate data' do
        expected_data = { '.encoding' => 'UTF-8',
                          'config.version' => '8',
                          'virtualHW.version' => '7',
                          'scsi0.present' => 'TRUE',
                          'scsi0.virtualDev' => 'lsilogic',
                          'memsize' => '384',
                          'scsi0:0.present' => 'TRUE',
                          'scsi0:0.fileName' => 'u10_04-000001.vmdk',
                          'ethernet0.present' => 'TRUE',
                          'ethernet0.connectionType' => 'nat',
                          'ethernet0.wakeOnPcktRcv' => 'FALSE',
                          'ethernet0.addressType' => 'generated',
                          'ethernet0.linkStatePropagation.enable' => 'TRUE',
                          'ehci.present' => 'TRUE',
                          'pciBridge4.virtualDev' => 'pcieRootPort',
                          'pciBridge4.functions' => '8',
                          'vmci0.present' => 'TRUE',
                          'roamingVM.exitBehavior' => 'go',
                          'tools.syncTime' => 'TRUE',
                          'displayName' => 'u10_04',
                          'guestOS' => 'ubuntu',
                          'nvram' => 'u10_04.nvram',
                          'virtualHW.productCompatibility' => 'hosted',
                          'tools.upgrade.policy' => 'upgradeAtPowerCycle',
                          'extendedConfigFile' => 'u10_04.vmxf',
                          'serial0.present' => 'FALSE',
                          'usb.present' => 'FALSE',
                          'checkpoint.vmState' => 'u10_04.vmss',
                          'ethernet0.generatedAddress' => '00:0c:29:c4:94:22',
                          'uuid.location' => '56 4d 4b e9 1a bb 22 3a-b0 91 06 4e b4 c4 94 22',
                          'uuid.bios' => '56 4d 4b e9 1a bb 22 3a-b0 91 06 4e b4 c4 94 22',
                          'cleanShutdown' => 'TRUE',
                          'scsi0:0.redo' => '',
                          'scsi0.pciSlotNumber' => '16',
                          'ethernet0.pciSlotNumber' => '32',
                          'ethernet0.generatedAddressOffset' => '0',
                          'vmci0.id' => '-1262185438',
                          'tools.remindInstall' => 'TRUE' }

        config = @vm_config.config_data
        config.data.should == expected_data
      end

    end
  end

end