naf 1.1.4 → 2.0.0
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.
- data/Gemfile +4 -2
- data/app/assets/images/{papertrail_job.png → job.png} +0 -0
- data/app/assets/images/{papertrail_machine.png → machine.png} +0 -0
- data/app/assets/images/{papertrail_machine_runner.png → machine_runner.png} +0 -0
- data/app/assets/javascripts/col_reorder_with_resize.js +1228 -0
- data/app/assets/javascripts/dataTablesTemplates/applications.js +2 -1
- data/app/assets/javascripts/dataTablesTemplates/jobs.js +2 -1
- data/app/assets/javascripts/dataTablesTemplates/machine_runner_invocations.js +2 -1
- data/app/assets/javascripts/dataTablesTemplates/machine_runners.js +2 -1
- data/app/assets/javascripts/dataTablesTemplates/machines.js +2 -1
- data/app/assets/javascripts/jquery.dataTables.js +10339 -5103
- data/app/assets/javascripts/naf.js +1 -0
- data/app/assets/stylesheets/jquery_ui/jquery-ui-1.8.5.custom.css.erb +6 -6
- data/app/assets/stylesheets/min_naf/layout.css.scss +94 -43
- data/app/assets/stylesheets/naf/layout.css.scss +94 -43
- data/app/controllers/naf/affinities_controller.rb +1 -1
- data/app/controllers/naf/applications_controller.rb +3 -0
- data/app/controllers/naf/historical_job_affinity_tabs_controller.rb +1 -1
- data/app/controllers/naf/historical_jobs_controller.rb +2 -5
- data/app/controllers/naf/log_parsers_controller.rb +16 -0
- data/app/controllers/naf/log_viewer_controller.rb +19 -0
- data/app/controllers/naf/machine_affinity_slots_controller.rb +1 -1
- data/app/controllers/naf/machine_runners_controller.rb +12 -0
- data/app/controllers/naf/machines_controller.rb +8 -10
- data/app/controllers/naf/status_controller.rb +12 -0
- data/app/helpers/naf/application_helper.rb +19 -38
- data/app/helpers/naf/time_helper.rb +37 -0
- data/app/models/logical/naf/application.rb +13 -19
- data/app/models/logical/naf/construction_zone/boss.rb +1 -1
- data/app/models/logical/naf/construction_zone/foreman.rb +1 -1
- data/app/models/logical/naf/job.rb +39 -34
- data/app/models/logical/naf/job_creator.rb +19 -23
- data/app/models/logical/naf/job_fetcher.rb +36 -6
- data/app/models/logical/naf/log_file.rb +70 -0
- data/app/models/logical/naf/log_parser/base.rb +272 -0
- data/app/models/logical/naf/log_parser/job.rb +65 -0
- data/app/models/logical/naf/log_parser/machine.rb +64 -0
- data/app/models/logical/naf/log_parser/runner.rb +72 -0
- data/app/models/logical/naf/log_reader.rb +85 -0
- data/app/models/logical/naf/machine.rb +39 -1
- data/app/models/naf/affinity.rb +18 -0
- data/app/models/naf/application_schedule_affinity_tab.rb +1 -0
- data/app/models/naf/application_type.rb +2 -1
- data/app/models/naf/historical_job.rb +9 -29
- data/app/models/naf/machine.rb +8 -0
- data/app/models/naf/machine_runner.rb +11 -2
- data/app/models/naf/machine_runner_invocation.rb +9 -1
- data/app/models/naf/running_job.rb +40 -1
- data/app/models/process/naf/application.rb +3 -3
- data/app/models/process/naf/log_archiver.rb +78 -0
- data/app/models/process/naf/machine_manager.rb +3 -1
- data/app/models/process/naf/runner.rb +286 -162
- data/app/models/process/naf/runner_log.rb +26 -0
- data/app/views/naf/application_schedule_affinity_tabs/_form.html.erb +1 -5
- data/app/views/naf/applications/show.html.erb +1 -1
- data/app/views/naf/historical_job_affinity_tabs/_form.html.erb +1 -5
- data/app/views/naf/historical_jobs/_form.html.erb +1 -1
- data/app/views/naf/historical_jobs/_runners.html.erb +21 -12
- data/app/views/naf/historical_jobs/_search_container.html.erb +1 -2
- data/app/views/naf/historical_jobs/index.html.erb +0 -1
- data/app/views/naf/historical_jobs/index.json.erb +4 -4
- data/app/views/naf/historical_jobs/show.html.erb +57 -51
- data/app/views/naf/log_viewer/_job_logs.html.erb +65 -0
- data/app/views/naf/log_viewer/_log_display.html.erb +259 -0
- data/app/views/naf/log_viewer/_log_layout.html.erb +59 -0
- data/app/views/naf/log_viewer/_machine_logs.html.erb +62 -0
- data/app/views/naf/log_viewer/_runner_logs.html.erb +62 -0
- data/app/views/naf/log_viewer/_search_options.html.erb +36 -0
- data/app/views/naf/log_viewer/_update_page_title.html.erb +9 -0
- data/app/views/naf/log_viewer/index.html.erb +1 -0
- data/app/views/naf/logger_names/_form.html.erb +1 -2
- data/app/views/naf/machine_affinity_slots/_form.html.erb +1 -5
- data/app/views/naf/machine_runner_invocations/show.html.erb +4 -0
- data/app/views/naf/machine_runners/show.html.erb +44 -34
- data/app/views/naf/machines/index.json.erb +14 -6
- data/app/views/naf/machines/show.html.erb +44 -40
- data/app/views/naf/shared/_auto_resize_width.html.erb +7 -0
- data/app/views/naf/shared/_date_select.html.erb +65 -0
- data/app/views/naf/shared/_select_per_page.html.erb +48 -13
- data/app/views/naf/status/index.html.erb +27 -0
- data/bin/naf +26 -0
- data/config/initializers/naf.rb +13 -1
- data/config/routes.rb +16 -2
- data/db/migrate/20131106162436_add_uuid_column_to_machine_runner_invocations.rb +15 -0
- data/db/migrate/20131121185222_move_tabs_column_from_historical_jobs_to_running_jobs.rb +15 -0
- data/lib/generators/templates/config/logging/naf.yml +0 -8
- data/lib/generators/templates/config/logging/nafjob.yml +0 -8
- data/lib/generators/templates/config/logging/nafrunner.yml +0 -8
- data/lib/generators/templates/naf.rb +0 -8
- data/lib/naf.rb +0 -8
- data/lib/naf/configuration.rb +0 -4
- data/lib/naf/version.rb +1 -1
- data/lib/tasks/naf_tasks.rake +18 -0
- data/naf.gemspec +3 -1
- data/spec/controllers/naf/affinities_controller_spec.rb +0 -1
- data/spec/controllers/naf/applications_controller_spec.rb +3 -2
- data/spec/controllers/naf/machine_affinity_slots_controller_spec.rb +0 -1
- data/spec/controllers/naf/machines_controller_spec.rb +1 -1
- data/spec/dummy/config/logging/naf.yml +0 -8
- data/spec/dummy/config/logging/nafjob.yml +0 -9
- data/spec/dummy/config/logging/nafrunner.yml +0 -10
- data/spec/factories/naf.rb +4 -0
- data/spec/models/logical/naf/application_spec.rb +3 -4
- data/spec/models/logical/naf/job_creator_spec.rb +91 -21
- data/spec/models/logical/naf/job_spec.rb +19 -6
- data/spec/models/logical/naf/log_file_spec.rb +105 -0
- data/spec/models/logical/naf/machine_runner_invocation_spec.rb +41 -0
- data/spec/models/logical/naf/machine_runner_spec.rb +42 -0
- data/spec/models/logical/naf/machine_spec.rb +98 -28
- data/spec/models/naf/affinity_classification_spec.rb +20 -0
- data/spec/models/naf/affinity_spec.rb +21 -0
- data/spec/models/naf/historical_job_spec.rb +2 -44
- data/spec/models/naf/machine_runner_invocation_spec.rb +17 -1
- data/spec/models/naf/running_job_spec.rb +64 -1
- metadata +40 -9
- data/app/models/log4r/papertrail_outputter.rb +0 -19
- data/app/views/naf/historical_jobs/edit.html.erb +0 -11
- data/app/views/naf/machines/_show.html.erb +0 -169
|
@@ -65,8 +65,9 @@ module Naf
|
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
context "on the create action" do
|
|
68
|
-
let(:
|
|
69
|
-
let(:
|
|
68
|
+
let(:application_schedule) { mock_model(ApplicationSchedule, application_run_group_name: 'command', prerequisites: []) }
|
|
69
|
+
let(:valid_app) { mock_model(Application, save: true, id: 5, update_attributes: true, application_schedule: application_schedule) }
|
|
70
|
+
let(:invalid_app) { mock_model(Application, save: false, update_attributes: false, application_schedule: application_schedule) }
|
|
70
71
|
|
|
71
72
|
it "should redirect to show when valid" do
|
|
72
73
|
Application.should_receive(:new).and_return(valid_app)
|
|
@@ -6,7 +6,6 @@ module Naf
|
|
|
6
6
|
let(:model_class) { MachineAffinitySlot}
|
|
7
7
|
|
|
8
8
|
it "should respond with index action nested under machine" do
|
|
9
|
-
model_class.should_receive(:where).with({ machine_id: "1" }).and_return([])
|
|
10
9
|
get :index, machine_id: 1
|
|
11
10
|
response.should render_template("naf/datatable")
|
|
12
11
|
response.should be_success
|
|
@@ -10,8 +10,8 @@ module Naf
|
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
it "should respond with the show action" do
|
|
13
|
+
machine = FactoryGirl.create(:machine, id: 5, server_address: '127.0.0.2')
|
|
13
14
|
id = 5
|
|
14
|
-
Machine.should_receive(:find).with("5").and_return(nil)
|
|
15
15
|
get :show, id: id
|
|
16
16
|
response.should be_success
|
|
17
17
|
end
|
|
@@ -12,11 +12,3 @@ log4r_config:
|
|
|
12
12
|
date_pattern: '%y%m%d %H:%M:%S.%L'
|
|
13
13
|
pattern : '%d pid=%p jid=%g %C %l %M'
|
|
14
14
|
type : PatternFormatter
|
|
15
|
-
|
|
16
|
-
- type: PapertrailOutputter
|
|
17
|
-
name: papertrail
|
|
18
|
-
port: 0 # XXX put your papertrail port here
|
|
19
|
-
program: naf_application
|
|
20
|
-
formatter:
|
|
21
|
-
pattern : 'pid=%p %C %l %M'
|
|
22
|
-
type : PatternFormatter
|
|
@@ -2,15 +2,6 @@ log4r_config:
|
|
|
2
2
|
outputters:
|
|
3
3
|
- type : StdoutOutputter
|
|
4
4
|
name : stdout
|
|
5
|
-
formatter:
|
|
6
|
-
date_pattern: '%y%m%d %H:%M:%S.%L'
|
|
7
|
-
pattern : '%d pid=%p jid=%g %C %l %M'
|
|
8
|
-
type : PatternFormatter
|
|
9
|
-
|
|
10
|
-
- type: PapertrailOutputter
|
|
11
|
-
name: papertrail
|
|
12
|
-
port: 0 # XXX put your papertrail port here
|
|
13
|
-
program: jid(%g)
|
|
14
5
|
formatter:
|
|
15
6
|
pattern : '%C %l %M'
|
|
16
7
|
type : PatternFormatter
|
|
@@ -2,16 +2,6 @@ log4r_config:
|
|
|
2
2
|
outputters:
|
|
3
3
|
- type : StdoutOutputter
|
|
4
4
|
name : stdout
|
|
5
|
-
level : DEBUG
|
|
6
|
-
formatter:
|
|
7
|
-
date_pattern: '%y%m%d %H:%M:%S.%L'
|
|
8
|
-
pattern : '%d runner_pid=%p %C %l %M'
|
|
9
|
-
type : PatternFormatter
|
|
10
|
-
|
|
11
|
-
- type: PapertrailOutputter
|
|
12
|
-
name: papertrail
|
|
13
|
-
port: 0 # XXX put your papertrail port here
|
|
14
|
-
program: runner
|
|
15
5
|
formatter:
|
|
16
6
|
pattern : '%C %l %M'
|
|
17
7
|
type : PatternFormatter
|
data/spec/factories/naf.rb
CHANGED
|
@@ -336,6 +336,10 @@ FactoryGirl.define do
|
|
|
336
336
|
end
|
|
337
337
|
end
|
|
338
338
|
|
|
339
|
+
factory :affinity_classification, class: ::Naf::AffinityClassification do
|
|
340
|
+
sequence(:affinity_classification_name) { |n| "affinity_classification_#{n}" }
|
|
341
|
+
end
|
|
342
|
+
|
|
339
343
|
#############################################################
|
|
340
344
|
####### Affinity Tabs and Slots #########################
|
|
341
345
|
#############################################################
|
|
@@ -17,7 +17,7 @@ module Logical
|
|
|
17
17
|
:prerequisites,
|
|
18
18
|
:deleted,
|
|
19
19
|
:visible] }
|
|
20
|
-
let(:physical_app) { FactoryGirl.create(:application) }
|
|
20
|
+
let(:physical_app) { FactoryGirl.create(:application, application_schedule: FactoryGirl.create(:schedule_base)) }
|
|
21
21
|
let!(:logical_app) { Application.new(physical_app) }
|
|
22
22
|
let(:scheduled_physical_app) {
|
|
23
23
|
FactoryGirl.create(:scheduled_application, application_schedule: FactoryGirl.create(:schedule_at_time))
|
|
@@ -25,9 +25,8 @@ module Logical
|
|
|
25
25
|
|
|
26
26
|
context "Class Methods" do
|
|
27
27
|
it "search method should return array of wrapper around physical application" do
|
|
28
|
-
|
|
29
|
-
Application.search(params: nil).
|
|
30
|
-
Application.search(params: nil).should have(1).items
|
|
28
|
+
Application.search(params: nil).map(&:id).should include(logical_app.id)
|
|
29
|
+
Application.search(params: nil).should have(2).items
|
|
31
30
|
Application.search(params: nil).should be_a(Array)
|
|
32
31
|
end
|
|
33
32
|
end
|
|
@@ -3,29 +3,99 @@ require 'spec_helper'
|
|
|
3
3
|
module Logical
|
|
4
4
|
module Naf
|
|
5
5
|
describe JobCreator do
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
6
|
+
|
|
7
|
+
let!(:job_creator) { ::Logical::Naf::JobCreator.new }
|
|
8
|
+
let!(:historical_job) { FactoryGirl.create(:job) }
|
|
9
|
+
let(:application) { FactoryGirl.create(:scheduled_application) }
|
|
10
|
+
|
|
11
|
+
describe '#queue_application' do
|
|
12
|
+
it 'not queue an application if the group limit is less than number of queued/running jobs' do
|
|
13
|
+
historical_job.application_run_group_name = application.application_schedule.application_run_group_name
|
|
14
|
+
historical_job.command = application.command
|
|
15
|
+
historical_job.save!
|
|
16
|
+
job_creator.create_queue_job(historical_job)
|
|
17
|
+
|
|
18
|
+
job_creator.queue_application(application,
|
|
19
|
+
application.application_schedule.application_run_group_restriction,
|
|
20
|
+
application.application_schedule.application_run_group_name).should be_nil
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'return a historical_job that has been queued' do
|
|
24
|
+
job_creator.queue_application(application,
|
|
25
|
+
application.application_schedule.application_run_group_restriction,
|
|
26
|
+
application.application_schedule.application_run_group_name).should be_instance_of(::Naf::HistoricalJob)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'create affinity tabs when affinities are present' do
|
|
30
|
+
job_creator.queue_application(application,
|
|
31
|
+
application.application_schedule.application_run_group_restriction,
|
|
32
|
+
application.application_schedule.application_run_group_name,
|
|
33
|
+
1,
|
|
34
|
+
0,
|
|
35
|
+
[::Naf::Affinity.first])
|
|
36
|
+
::Naf::HistoricalJobAffinityTab.should have(1).records
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe '#retrieve_jobs' do
|
|
41
|
+
before do
|
|
42
|
+
FactoryGirl.create(:queued_job, application_run_group_name: 'Test',
|
|
43
|
+
application_run_group_limit: 1)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it 'return the correct records' do
|
|
47
|
+
job_creator.retrieve_jobs(::Naf::QueuedJob, '::Naf::QueuedJob.test hello world', 'Test').
|
|
48
|
+
count.to_i.should == 1
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe '#queue_application_schedule' do
|
|
53
|
+
it 'raise error if schedule has been queued' do
|
|
54
|
+
expect { job_creator.queue_application_schedule(application.application_schedule, [application.application_schedule.id]) }.
|
|
55
|
+
to raise_error(::Naf::HistoricalJob::JobPrerequisiteLoop)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it 'return a historical_job that has been queued' do
|
|
59
|
+
job_creator.queue_application_schedule(application.application_schedule).should be_instance_of(::Naf::HistoricalJob)
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
describe '#queue_rails_job' do
|
|
64
|
+
it 'create and return a historical_job' do
|
|
65
|
+
job = job_creator.queue_rails_job(:command)
|
|
66
|
+
job.should be_instance_of(::Naf::HistoricalJob)
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it 'create affinity tabs when affinites are present' do
|
|
70
|
+
job_creator.queue_rails_job(:command,
|
|
71
|
+
::Naf::ApplicationRunGroupRestriction.limited_per_all_machines,
|
|
72
|
+
:command,
|
|
73
|
+
1,
|
|
74
|
+
0,
|
|
75
|
+
[::Naf::Affinity.first])
|
|
76
|
+
|
|
77
|
+
::Naf::HistoricalJobAffinityTab.should have(1).records
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
describe '#verify_and_create_prerequisites' do
|
|
82
|
+
before do
|
|
83
|
+
prereq_job = FactoryGirl.create(:job)
|
|
84
|
+
job_creator.verify_and_create_prerequisites(historical_job, [prereq_job])
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
it 'insert a row correctly into naf.historical_job_prerequisites' do
|
|
88
|
+
::Naf::HistoricalJobPrerequisite.should have(1).records
|
|
27
89
|
end
|
|
28
90
|
end
|
|
91
|
+
|
|
92
|
+
describe '#create_queue_job' do
|
|
93
|
+
it 'insert a row correctly into naf.queued_jobs' do
|
|
94
|
+
job_creator.create_queue_job(historical_job)
|
|
95
|
+
::Naf::QueuedJob.should have(1).records
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
29
99
|
end
|
|
30
100
|
|
|
31
101
|
end
|
|
@@ -203,10 +203,18 @@ module Logical
|
|
|
203
203
|
job.run_time.should == '0h0m6s'
|
|
204
204
|
end
|
|
205
205
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
206
|
+
describe "show correct run time when job is running" do
|
|
207
|
+
it "less than 2 days" do
|
|
208
|
+
historical_job.started_at = Time.zone.now - 3.hours
|
|
209
|
+
historical_job.finished_at = nil
|
|
210
|
+
job.run_time.should == '3h0m0s'
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
it "more than 2 days" do
|
|
214
|
+
historical_job.started_at = Time.zone.now - 3.days
|
|
215
|
+
historical_job.finished_at = nil
|
|
216
|
+
job.run_time.should == '3d0h0m0s'
|
|
217
|
+
end
|
|
210
218
|
end
|
|
211
219
|
|
|
212
220
|
it "show correct run time when job has not started" do
|
|
@@ -262,13 +270,18 @@ module Logical
|
|
|
262
270
|
end
|
|
263
271
|
|
|
264
272
|
describe "#tags" do
|
|
273
|
+
before do
|
|
274
|
+
running_job = FactoryGirl.create(:running_job_base, historical_job: historical_job)
|
|
275
|
+
historical_job.running_job = running_job
|
|
276
|
+
end
|
|
277
|
+
|
|
265
278
|
it "show custom visible tags" do
|
|
266
|
-
historical_job.tags = '{test}'
|
|
279
|
+
historical_job.running_job.tags = '{test}'
|
|
267
280
|
job.tags.should == 'test'
|
|
268
281
|
end
|
|
269
282
|
|
|
270
283
|
it "not show system or custom invisible tags" do
|
|
271
|
-
historical_job.tags = '{$test,_test}'
|
|
284
|
+
historical_job.running_job.tags = '{$test,_test}'
|
|
272
285
|
job.tags.should == ''
|
|
273
286
|
end
|
|
274
287
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Logical
|
|
4
|
+
module Naf
|
|
5
|
+
describe LogFile do
|
|
6
|
+
|
|
7
|
+
before(:all) do
|
|
8
|
+
Timecop.freeze(Time.zone.now)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
after(:all) do
|
|
12
|
+
Timecop.return
|
|
13
|
+
`rm -rf log_spec/`
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
let!(:log_file) { ::Logical::Naf::LogFile.new('log_spec') }
|
|
17
|
+
let!(:time) { Time.zone.now }
|
|
18
|
+
let!(:log_line) {
|
|
19
|
+
JSON.pretty_generate({
|
|
20
|
+
line_number: 1,
|
|
21
|
+
output_time: time.strftime("%Y-%m-%d %H:%M:%S.%L"),
|
|
22
|
+
message: 'test message'
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
describe '<<' do
|
|
27
|
+
before do
|
|
28
|
+
log_file << 'test message'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it 'encapsulate the message in JSON format' do
|
|
32
|
+
log_file.lines_cache.should == log_line
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it 'increment the line_number' do
|
|
36
|
+
log_file.line_number.should == 2
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
describe 'write' do
|
|
41
|
+
before do
|
|
42
|
+
log_file.open
|
|
43
|
+
log_file << 'test message'
|
|
44
|
+
log_file.write
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'clear the lines_cache' do
|
|
48
|
+
log_file.lines_cache.should == ''
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'save the logs to the file' do
|
|
52
|
+
File.open(log_file.file.path, 'r').read.should == log_line
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe 'flush' do
|
|
57
|
+
before do
|
|
58
|
+
log_file.open
|
|
59
|
+
log_file.file.write('test message')
|
|
60
|
+
log_file.flush
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'update the file with content written' do
|
|
64
|
+
File.open(log_file.file.path, 'r').read.should == 'test message'
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
describe 'open' do
|
|
69
|
+
before do
|
|
70
|
+
log_file.open
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
it 'create the file path' do
|
|
74
|
+
log_file.file.path.should == "log_spec/1_#{time.strftime('%Y%m%d_%H%M%S')}.json"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe 'close' do
|
|
79
|
+
before do
|
|
80
|
+
log_file.open
|
|
81
|
+
log_file.close
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it 'close the file stream' do
|
|
85
|
+
log_file.file.should == nil
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
describe 'check_file_size' do
|
|
90
|
+
before do
|
|
91
|
+
log_file.open
|
|
92
|
+
log_file << 'test message'
|
|
93
|
+
log_file.write
|
|
94
|
+
stub_const('::Logical::Naf::LogFile::LOG_MAX_SIZE', 1)
|
|
95
|
+
log_file.check_file_size
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
it 'create a new file when size > LOG_MAX_SIZE' do
|
|
99
|
+
log_file.file.path.should == "log_spec/2_#{time.strftime('%Y%m%d_%H%M%S')}.json"
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Logical
|
|
4
|
+
module Naf
|
|
5
|
+
|
|
6
|
+
describe MachineRunnerInvocation do
|
|
7
|
+
|
|
8
|
+
let!(:machine_runner) { FactoryGirl.create(:machine_runner) }
|
|
9
|
+
let!(:machine) { ::Logical::Naf::Machine.new(machine_runner.machine) }
|
|
10
|
+
let!(:invocation1) { FactoryGirl.create(:machine_runner_invocation, machine_runner: machine_runner) }
|
|
11
|
+
let!(:invocation2) { FactoryGirl.create(:machine_runner_invocation, machine_runner: machine_runner) }
|
|
12
|
+
let!(:invocations) {
|
|
13
|
+
[[invocation1.id,
|
|
14
|
+
invocation1.created_at.to_s,
|
|
15
|
+
invocation1.machine_runner_id,
|
|
16
|
+
[machine.id, machine.name.to_s],
|
|
17
|
+
invocation1.pid,
|
|
18
|
+
invocation1.status.gsub('-', ' ').split.map(&:capitalize).join(' '),
|
|
19
|
+
invocation1.commit_information,
|
|
20
|
+
invocation1.deployment_tag,
|
|
21
|
+
invocation1.repository_name],
|
|
22
|
+
[invocation2.id,
|
|
23
|
+
invocation2.created_at.to_s,
|
|
24
|
+
invocation2.machine_runner_id,
|
|
25
|
+
[machine.id, machine.name.to_s],
|
|
26
|
+
invocation2.pid,
|
|
27
|
+
invocation2.status.gsub('-', ' ').split.map(&:capitalize).join(' '),
|
|
28
|
+
invocation2.commit_information,
|
|
29
|
+
invocation2.deployment_tag,
|
|
30
|
+
invocation2.repository_name]]
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
describe '#to_array' do
|
|
34
|
+
it 'return invocation information in correct order' do
|
|
35
|
+
::Logical::Naf::MachineRunnerInvocation.to_array(0, 'asc', nil).should == invocations
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
module Logical
|
|
4
|
+
module Naf
|
|
5
|
+
|
|
6
|
+
describe MachineRunner do
|
|
7
|
+
|
|
8
|
+
let!(:machine_runner1) { FactoryGirl.create(:machine_runner) }
|
|
9
|
+
let!(:machine_runner2) { FactoryGirl.create(:machine_runner) }
|
|
10
|
+
let!(:machine) { ::Logical::Naf::Machine.new(machine_runner1.machine) }
|
|
11
|
+
let!(:invocation1) { FactoryGirl.create(:machine_runner_invocation, machine_runner: machine_runner1) }
|
|
12
|
+
let!(:invocation2) { FactoryGirl.create(:machine_runner_invocation, machine_runner: machine_runner2) }
|
|
13
|
+
let!(:invocations) {
|
|
14
|
+
[[machine_runner1.id,
|
|
15
|
+
machine_runner1.created_at.to_s,
|
|
16
|
+
machine.id,
|
|
17
|
+
machine_runner1.runner_cwd,
|
|
18
|
+
invocation1.id,
|
|
19
|
+
invocation1.pid,
|
|
20
|
+
invocation1.status.gsub('-', ' ').split.map(&:capitalize).join(' '),
|
|
21
|
+
0,
|
|
22
|
+
''],
|
|
23
|
+
[machine_runner2.id,
|
|
24
|
+
machine_runner2.created_at.to_s,
|
|
25
|
+
machine.id,
|
|
26
|
+
machine_runner2.runner_cwd,
|
|
27
|
+
invocation2.id,
|
|
28
|
+
invocation2.pid,
|
|
29
|
+
invocation2.status.gsub('-', ' ').split.map(&:capitalize).join(' '),
|
|
30
|
+
0,
|
|
31
|
+
'']]
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
describe '#to_array' do
|
|
35
|
+
it 'return invocation information in correct order' do
|
|
36
|
+
::Logical::Naf::MachineRunner.to_array(0, 'asc').should == invocations
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|