oneacct-export 0.2.6 → 0.2.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a8ec2b00918ec5fec106d4cae21103fd5d373f1
4
- data.tar.gz: bd243d18fb461e681d6e96c36cc0597f13e11c5b
3
+ metadata.gz: 841473513aa37713ab102ac8b54d85d05fd52b75
4
+ data.tar.gz: c3195af5db1345b1471fb28e90909e01200525fb
5
5
  SHA512:
6
- metadata.gz: a075db4e55f76c87d951c7c3e8325f41213eb8d05e8fccbdb26d0f2ab6bc3b7eaf821f874cf0a2e3e3e851ad7e1a6df91de8ef1496ecff0851da749a4cc0d444
7
- data.tar.gz: 37f5e20dfe9e431fa9d8ba6c08805ec805bd5f8dc3f8f1c462022e24058dedd135d2b29bb5ac23939e49b4077b12b109e4b0de9b9d7b3485fdcd24ced640dde2
6
+ metadata.gz: d09c93b909f2c534a62c3c58d8cc5d70a4d82d9ceba4725b8a983d5d584bf15a3680fcdf63631c615c25e68145ae3c6da66eab46e890b3776857f291e883cda4
7
+ data.tar.gz: 92039510265e1bd5decbd534e79e67c324ce069faedad79e9d6fbd2e466f1107aa01d63df970f2bc9fa3954a146d14e72b8fabdedd9a001af693f4af6ccd1640
@@ -172,7 +172,7 @@ class OneWorker
172
172
  rstime = 0
173
173
  vm.each 'HISTORY_RECORDS/HISTORY' do |h|
174
174
  next unless h['RSTIME'] && h['RETIME'] && h['RSTIME'] != '0'
175
- if h['RETIME'] == '0'
175
+ if h['RETIME'] == '0' && STATES[vm['STATE'].to_i] != 'completed'
176
176
  rstime += Time.now.to_i - h['RSTIME'].to_i
177
177
  next
178
178
  end
@@ -213,8 +213,8 @@ class OneWorker
213
213
  # Sidekiq specific method, specifies the purpose of the worker
214
214
  #
215
215
  # @param [String] vms IDs of virtual machines to process in form of numbers separated by '|' (easier for cooperation with redis)
216
- # @param [String] output output directory
217
- def perform(vms, output)
216
+ # @param [String] file_number number of the output file
217
+ def perform(vms, file_number)
218
218
  OneacctExporter::Log.setup_log_level(logger)
219
219
 
220
220
  vms = vms.split('|')
@@ -237,16 +237,16 @@ class OneWorker
237
237
  data << vm_data
238
238
  end
239
239
 
240
- write_data(data, output)
240
+ write_data(data, file_number)
241
241
  end
242
242
 
243
243
  # Write processed data into output directory
244
- def write_data(data, output)
244
+ def write_data(data, file_number)
245
245
  logger.debug('Creating writer...')
246
- ow = OneWriter.new(data, output, logger)
246
+ ow = OneWriter.new(data, file_number, logger)
247
247
  ow.write
248
248
  rescue => e
249
- msg = "Cannot write result to #{output}: #{e.message}"
249
+ msg = "Cannot write result: #{e.message}"
250
250
  logger.error(msg)
251
251
  raise msg
252
252
  end
@@ -7,21 +7,26 @@ require 'logger'
7
7
  # Class responsible for writing data into files in specific format
8
8
  #
9
9
  # @attr_reader [Hash] data vm data
10
- # @attr_reader [String] output path to the output directory
10
+ # @attr_reader [String] output path to the output file
11
11
  # @attr_reader [any logger] logger
12
12
  class OneWriter
13
+ APEL_FILENAME_FORMAT = '%014d'
13
14
 
14
15
  attr_reader :data, :output, :log
15
16
 
16
- def initialize(data, output, log = Logger.new(STDOUT))
17
- fail ArgumentError, 'Data and output cannot be nil' if data.nil? || output.nil?
17
+ def initialize(data, file_number, log = Logger.new(STDOUT))
18
+ fail ArgumentError, 'Data and file number cannot be nil' if data.nil? || file_number.nil?
18
19
 
19
- @template = OneWriter.template_filename(Settings.output['output_type']) if Settings['output']
20
+ output_type = Settings.output['output_type']
21
+ @template = OneWriter.template_filename(output_type) if Settings['output']
20
22
  fail ArgumentError, "No such file: #{@template}." unless File.exist?(@template)
21
23
 
22
24
  @data = data
23
- @output = output
24
25
  @log = log
26
+
27
+ filename = file_number.to_s
28
+ filename = APEL_FILENAME_FORMAT % file_number if output_type == 'apel-0.2'
29
+ @output = "#{Settings.output['output_dir']}/#{filename}"
25
30
  end
26
31
 
27
32
  # Write data to file in output directory
@@ -13,7 +13,6 @@ require 'sidekiq/api'
13
13
  # @attr_reader [Integer] timeout timeout for blocking mode
14
14
  # @attr_reader [TrueClass, FalseClass] compatibility says whether to run export in compatibility mode or not
15
15
  class OneacctExporter
16
- CONVERT_FORMAT = '%014d'
17
16
 
18
17
  attr_reader :log, :range, :groups, :blocking, :timeout, :compatibility
19
18
 
@@ -39,11 +38,10 @@ class OneacctExporter
39
38
  vms = []
40
39
  #load records of virtual machines in batches
41
40
  while vms = oda.vms(batch_number, @range, @groups)
42
- output_file = CONVERT_FORMAT % new_file_number
43
41
  @log.info("Starting worker with batch number: #{batch_number}.")
44
42
  unless vms.empty?
45
43
  #add a new job for every batch to the Sidekiq's queue
46
- OneWorker.perform_async(vms.join('|'), "#{Settings.output['output_dir']}/#{output_file}")
44
+ OneWorker.perform_async(vms.join('|'), new_file_number)
47
45
  new_file_number += 1
48
46
  end
49
47
  batch_number += 1
@@ -1,3 +1,3 @@
1
1
  class OneacctExporter
2
- VERSION = '0.2.6'
2
+ VERSION = '0.2.7'
3
3
  end
@@ -0,0 +1,115 @@
1
+ <VM>
2
+ <ID>36551</ID>
3
+ <UID>120</UID>
4
+ <GID>0</GID>
5
+ <UNAME>uname</UNAME>
6
+ <GNAME>gname</GNAME>
7
+ <NAME>one-36551</NAME>
8
+ <PERMISSIONS>
9
+ <OWNER_U>1</OWNER_U>
10
+ <OWNER_M>1</OWNER_M>
11
+ <OWNER_A>0</OWNER_A>
12
+ <GROUP_U>0</GROUP_U>
13
+ <GROUP_M>0</GROUP_M>
14
+ <GROUP_A>0</GROUP_A>
15
+ <OTHER_U>0</OTHER_U>
16
+ <OTHER_M>0</OTHER_M>
17
+ <OTHER_A>0</OTHER_A>
18
+ </PERMISSIONS>
19
+ <LAST_POLL>1383741679</LAST_POLL>
20
+ <STATE>4</STATE>
21
+ <LCM_STATE>0</LCM_STATE>
22
+ <RESCHED>0</RESCHED>
23
+ <STIME>1383741160</STIME>
24
+ <ETIME>1383742270</ETIME>
25
+ <DEPLOY_ID>one-36551</DEPLOY_ID>
26
+ <MEMORY>1736960</MEMORY>
27
+ <CPU>0</CPU>
28
+ <NET_TX>0</NET_TX>
29
+ <NET_RX>0</NET_RX>
30
+ <TEMPLATE>
31
+ <CONTEXT>
32
+ <DISK_ID><![CDATA[1]]></DISK_ID>
33
+ <FILES><![CDATA[https://somewhere.com/init.sh]]></FILES>
34
+ <HOSTNAME><![CDATA[DebianVM]]></HOSTNAME>
35
+ <PUBLIC_IP><![CDATA[123.123.5.5]]></PUBLIC_IP>
36
+ <SSH_KEY><![CDATA[ssh-rsa AAAAB3NzaC1yc2EAAAADAQABasdgsdfhfgjhxhcHPNFthrHT5/+9lfrQCorJy5YjMJEGBC22dfgjghkDjSDFgjdhgKd54645dfJKd39LdlyzlEaCnjGUeD4C6tZdAISLSDfghSDFgSJ54sSFGJ5RTHARJIRJcX8QRVH46Zq02AeTgrty567ss34tqaa8Pt user@machine1.somewhere.com]]></SSH_KEY>
37
+ <TARGET><![CDATA[xvdb]]></TARGET>
38
+ </CONTEXT>
39
+ <CPU><![CDATA[0.5]]></CPU>
40
+ <DISK>
41
+ <BUS><![CDATA[ide]]></BUS>
42
+ <CLONE><![CDATA[YES]]></CLONE>
43
+ <CLUSTER_ID><![CDATA[100]]></CLUSTER_ID>
44
+ <DATASTORE><![CDATA[default]]></DATASTORE>
45
+ <DATASTORE_ID><![CDATA[1]]></DATASTORE_ID>
46
+ <DEV_PREFIX><![CDATA[xvd]]></DEV_PREFIX>
47
+ <DISK_ID><![CDATA[0]]></DISK_ID>
48
+ <DRIVER><![CDATA[tap2:tapdisk:aio:]]></DRIVER>
49
+ <IMAGE><![CDATA[debian6]]></IMAGE>
50
+ <IMAGE_ID><![CDATA[31]]></IMAGE_ID>
51
+ <READONLY><![CDATA[NO]]></READONLY>
52
+ <SAVE><![CDATA[NO]]></SAVE>
53
+ <SOURCE><![CDATA[/opt/opennebula/var/datastores/1/bc8db254875412f417ac745b7d47820]]></SOURCE>
54
+ <TARGET><![CDATA[xvda]]></TARGET>
55
+ <TM_MAD><![CDATA[ssh]]></TM_MAD>
56
+ <TYPE><![CDATA[FILE]]></TYPE>
57
+ </DISK>
58
+ <ERROR>
59
+ <MESSAGE><![CDATA[Error executing image transfer script: Path https://somewhere.com/init.sh is not allowed!]]></MESSAGE>
60
+ <TIMESTAMP><![CDATA[Wed Nov 6 13:34:19 2013]]></TIMESTAMP>
61
+ </ERROR>
62
+ <FEATURES>
63
+ <ACPI><![CDATA[no]]></ACPI>
64
+ </FEATURES>
65
+ <MEMORY>1736960</MEMORY>
66
+ <NAME><![CDATA[one-36551]]></NAME>
67
+ <NIC>
68
+ <BRIDGE><![CDATA[xenbr0]]></BRIDGE>
69
+ <CLUSTER_ID><![CDATA[100]]></CLUSTER_ID>
70
+ <IP><![CDATA[123.123.5.5]]></IP>
71
+ <MAC><![CDATA[01:23:45:67:89:ab]]></MAC>
72
+ <NETWORK><![CDATA[public]]></NETWORK>
73
+ <NETWORK_ID><![CDATA[4]]></NETWORK_ID>
74
+ <VLAN><![CDATA[NO]]></VLAN>
75
+ <WHITE_PORTS_TCP><![CDATA[22]]></WHITE_PORTS_TCP>
76
+ <WHITE_PORTS_UDP><![CDATA[67,68]]></WHITE_PORTS_UDP>
77
+ </NIC>
78
+ <OS>
79
+ <BOOTLOADER><![CDATA[pygrub]]></BOOTLOADER>
80
+ </OS>
81
+ <RAW>
82
+ <TYPE><![CDATA[xen]]></TYPE>
83
+ </RAW>
84
+ <TEMPLATE_ID><![CDATA[66]]></TEMPLATE_ID>
85
+ <VCPU><![CDATA[1]]></VCPU>
86
+ <VMID><![CDATA[36551]]></VMID>
87
+ </TEMPLATE>
88
+ <USER_TEMPLATE>
89
+ <SCHED_REQUIREMENTS><![CDATA[CLUSTER_ID = 100]]></SCHED_REQUIREMENTS>
90
+ </USER_TEMPLATE>
91
+ <HISTORY_RECORDS>
92
+ <HISTORY>
93
+ <OID>36551</OID>
94
+ <SEQ>1</SEQ>
95
+ <HOSTNAME>supermachine1.somewhere.com</HOSTNAME>
96
+ <HID>11</HID>
97
+ <CID>100</CID>
98
+ <STIME>1383741589</STIME>
99
+ <ETIME>1383742270</ETIME>
100
+ <VMMMAD>vmm_xen</VMMMAD>
101
+ <VNMMAD>fw</VNMMAD>
102
+ <TMMAD>ssh</TMMAD>
103
+ <DS_LOCATION>/opt/opennebula/var/datastores</DS_LOCATION>
104
+ <DS_ID>0</DS_ID>
105
+ <PSTIME>1383741589</PSTIME>
106
+ <PETIME>1383741674</PETIME>
107
+ <RSTIME>1383741674</RSTIME>
108
+ <RETIME>0</RETIME>
109
+ <ESTIME>1383742270</ESTIME>
110
+ <EETIME>1383742270</EETIME>
111
+ <REASON>0</REASON>
112
+ <ACTION>0</ACTION>
113
+ </HISTORY>
114
+ </HISTORY_RECORDS>
115
+ </VM>
@@ -680,18 +680,26 @@ describe OneWorker do
680
680
  end
681
681
  end
682
682
 
683
- context 'vm with RETIME that is 0' do
683
+ context 'vm with RETIME that is 0 and still running' do
684
684
  before :example do
685
- allow(Time).to receive(:now) { 1383741716 }
685
+ allow(Time).to receive(:now) { Time.at(1383741716) }
686
686
  end
687
687
 
688
- let(:filename) { 'one_worker_RETIME_0.xml' }
688
+ let(:filename) { 'one_worker_RETIME_0_RUNNING.xml' }
689
689
 
690
690
  it 'returns difference between current time and start of the virtual machine' do
691
691
  expect(subject.sum_rstime(vm)).to eq(42)
692
692
  end
693
693
  end
694
694
 
695
+ context 'vm with RETIME that is 0 and is stopped' do
696
+ let(:filename) { 'one_worker_RETIME_0_STOPPED.xml' }
697
+
698
+ it 'returns nil' do
699
+ expect(subject.sum_rstime(vm)).to be_nil
700
+ end
701
+ end
702
+
695
703
  context 'vm with RSTIME bigger than RETIME' do
696
704
  let(:filename) { 'one_worker_RSTIME_>_RETIME.xml' }
697
705
 
@@ -4,12 +4,13 @@ describe OneWriter do
4
4
  subject { one_writer }
5
5
  before :example do
6
6
  Settings.output['output_type'] = 'one_writer_test_output_type'
7
+ Settings.output['output_dir'] = 'one_writer_test_output_dir'
7
8
  end
8
9
 
9
10
  let(:data) { { 'aaa' => 111, 'bbb' => 222 } }
10
11
  let(:testfile) { "#{GEM_DIR}/mock/one_writer_testfile" }
11
12
  let(:dev_null) { '/dev/null' }
12
- let(:output) { "#{GEM_DIR}/mock/one_writer_output" }
13
+ let(:file_number) { 42 }
13
14
 
14
15
  describe '#new' do
15
16
  context 'with correct arguments' do
@@ -18,7 +19,7 @@ describe OneWriter do
18
19
  end
19
20
 
20
21
  let(:one_writer) do
21
- OneWriter.new(data, output, dev_null)
22
+ OneWriter.new(data, file_number, dev_null)
22
23
  end
23
24
 
24
25
  it 'takes three parameters and returns OneWriter object' do
@@ -27,11 +28,26 @@ describe OneWriter do
27
28
 
28
29
  it 'correctly assigns three parameters' do
29
30
  expect(subject.data).to eq(data)
30
- expect(subject.output).to eq(output)
31
+ expect(subject.output).to eq("#{Settings.output['output_dir']}/#{file_number}")
31
32
  expect(subject.log).to eq(dev_null)
32
33
  end
33
34
  end
34
35
 
36
+ context 'with apel output format' do
37
+ before :example do
38
+ Settings.output['output_type'] = 'apel-0.2'
39
+ allow(OneWriter).to receive(:template_filename) { testfile }
40
+ end
41
+
42
+ let(:one_writer) do
43
+ OneWriter.new(data, file_number, dev_null)
44
+ end
45
+
46
+ it 'uses apel specific filename format' do
47
+ expect(subject.output).to eq("#{Settings.output['output_dir']}/000000000000#{file_number}")
48
+ end
49
+ end
50
+
35
51
  context 'with incorrect arguments' do
36
52
  before :example do
37
53
  allow(OneWriter).to receive(:template_filename) { testfile }
@@ -128,7 +144,7 @@ describe OneWriter do
128
144
  end
129
145
 
130
146
  let(:one_writer) do
131
- OneWriter.new(data, output, Logger.new(dev_null))
147
+ OneWriter.new(data, file_number, Logger.new(dev_null))
132
148
  end
133
149
  let(:tmp) do
134
150
  tmp = double('tmp')
@@ -138,7 +154,7 @@ describe OneWriter do
138
154
 
139
155
  it 'writes result version of a template into output file' do
140
156
  expect(subject).to receive(:write_to_tmp).with(tmp, data)
141
- expect(subject).to receive(:copy_to_output).with("#{GEM_DIR}/mock/one_writer_tmp", output)
157
+ expect(subject).to receive(:copy_to_output).with("#{GEM_DIR}/mock/one_writer_tmp", "#{Settings.output['output_dir']}/#{file_number}")
142
158
  expect(tmp).to receive(:close)
143
159
  subject.write
144
160
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oneacct-export
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.2.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Kimle
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-25 00:00:00.000000000 Z
11
+ date: 2015-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -198,7 +198,8 @@ files:
198
198
  - mock/one_worker_NET_TX_0.xml
199
199
  - mock/one_worker_NET_TX_missing.xml
200
200
  - mock/one_worker_NET_TX_nan.xml
201
- - mock/one_worker_RETIME_0.xml
201
+ - mock/one_worker_RETIME_0_RUNNING.xml
202
+ - mock/one_worker_RETIME_0_STOPPED.xml
202
203
  - mock/one_worker_RETIME_missing.xml
203
204
  - mock/one_worker_RSTIME_0.xml
204
205
  - mock/one_worker_RSTIME_>_RETIME.xml