diff --git a/astute/bin/astute b/astute/bin/astute index dd169b21a..2810cc5c7 100755 --- a/astute/bin/astute +++ b/astute/bin/astute @@ -41,6 +41,15 @@ Astute.logger = Logger.new(STDOUT) if opts[:verbose] environment = YAML.load_file(opts[:filename]) -orchestrator = Astute::Orchestrator.new(nil, log_parsing=false) +case environment['attributes']['deployment_engine'] + when 'nailyfact' + deploy_engine = Astute::DeploymentEngine::NailyFact + when 'simplepuppet' + deploy_engine = Astute::DeploymentEngine::SimplePuppet # It just calls puppet and doesn't do any magic + else + deploy_engine = nil # Orchestrator will use it's default +end + +orchestrator = Astute::Orchestrator.new(deploy_engine, log_parsing=false) orchestrator.deploy(reporter, environment['task_uuid'], environment['nodes'], environment['attributes']) #orchestrator.verify_networks(reporter, task_id, nodes, networks) diff --git a/astute/examples/no_attrs.yaml b/astute/examples/no_attrs.yaml new file mode 100644 index 000000000..83670502f --- /dev/null +++ b/astute/examples/no_attrs.yaml @@ -0,0 +1,12 @@ +--- +nodes: +- status: provisioned + role: controller + uid: devnailgun.mirantis.com +- status: provisioned + role: compute + uid: devnailgun.mirantis.com +attributes: + deployment_mode: multinode_compute + deployment_engine: simplepuppet +task_uuid: deployment_task diff --git a/astute/examples/test_env.yaml b/astute/examples/test_env.yaml index ae9dcb283..6a4eb9167 100644 --- a/astute/examples/test_env.yaml +++ b/astute/examples/test_env.yaml @@ -59,6 +59,8 @@ nodes: uid: devnailgun.mirantis.com mac: 52:54:00:50:91:DD attributes: + deployment_mode: multinode_compute + deployment_engine: nailyfact glance: db_password: glance user_password: glance diff --git a/astute/lib/astute/deployment_engine.rb b/astute/lib/astute/deployment_engine.rb index 0de912502..9307a1352 100644 --- a/astute/lib/astute/deployment_engine.rb +++ b/astute/lib/astute/deployment_engine.rb @@ -7,15 +7,17 @@ PUPPET_FADE_TIMEOUT = 60 module Astute class DeploymentEngine def initialize(context) + if self.class.superclass.name == 'Object' + raise "Instantiation of this superclass is not allowed. Please subclass from #{self.class.name}." + end @ctx = context end def deploy(nodes, attrs) + # See implementation in subclasses, this may be everriden attrs['deployment_mode'] ||= 'multinode_compute' # simple multinode deployment is the default - nodes.each {|n| n['uid'] = n['uid'].to_s } # It may fail if uid is Fixnum - Astute.logger.info "Deployment mode #{attrs['deployment_mode']}, using #{self.class} for deployment." - attrs_for_mode = self.send("attrs_#{attrs['deployment_mode']}", nodes, attrs) - result = self.send("deploy_#{attrs['deployment_mode']}", nodes, attrs_for_mode) + Astute.logger.info "Deployment mode #{attrs['deployment_mode']}" + result = self.send("deploy_#{attrs['deployment_mode']}", nodes, attrs) end def method_missing(method, *args) diff --git a/astute/lib/astute/deployment_engine/nailyfact.rb b/astute/lib/astute/deployment_engine/nailyfact.rb index f2500df9f..bd33a97ff 100644 --- a/astute/lib/astute/deployment_engine/nailyfact.rb +++ b/astute/lib/astute/deployment_engine/nailyfact.rb @@ -1,5 +1,10 @@ class Astute::DeploymentEngine::NailyFact < Astute::DeploymentEngine + def deploy(nodes, attrs) + attrs_for_mode = self.send("attrs_#{attrs['deployment_mode']}", nodes, attrs) + super(nodes, attrs_for_mode) + end + def create_facts(node, attrs) metapublisher = Astute::Metadata.method(:publish_facts) # calculate_networks method is common and you can find it in superclass diff --git a/astute/lib/astute/deployment_engine/simple_puppet.rb b/astute/lib/astute/deployment_engine/simple_puppet.rb index d01f85421..19d285fdc 100644 --- a/astute/lib/astute/deployment_engine/simple_puppet.rb +++ b/astute/lib/astute/deployment_engine/simple_puppet.rb @@ -3,8 +3,8 @@ class Astute::DeploymentEngine::SimplePuppet < Astute::DeploymentEngine # with all required parameters for modules def deploy_piece(nodes, *args) return false unless validate_nodes(nodes) + @ctx.reporter.report nodes_status(nodes, 'deploying') Astute::PuppetdDeployer.deploy(@ctx, nodes) - @ctx.reporter.report nodes_status(nodes, 'ready') nodes_roles = nodes.map { |n| { n['uid'] => n['role'] } } Astute.logger.info "#{@ctx.task_id}: Finished deployment of nodes => roles: #{nodes_roles.inspect}" end diff --git a/astute/lib/astute/orchestrator.rb b/astute/lib/astute/orchestrator.rb index ab5ff27f8..5b79d5c5d 100644 --- a/astute/lib/astute/orchestrator.rb +++ b/astute/lib/astute/orchestrator.rb @@ -26,6 +26,7 @@ module Astute proxy_reporter = ProxyReporter.new(up_reporter) context = Context.new(task_id, proxy_reporter, @log_parser) deploy_engine_instance = @deploy_engine.new(context) + Astute.logger.info "Using #{deploy_engine_instance.class} for deployment." deploy_engine_instance.deploy(nodes, attrs) end diff --git a/astute/spec/unit/deployment_engine_spec.rb b/astute/spec/unit/deployment_engine_spec.rb deleted file mode 100644 index dfc689045..000000000 --- a/astute/spec/unit/deployment_engine_spec.rb +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env rspec -require File.join(File.dirname(__FILE__), "..", "spec_helper") - -describe "DeploymentEngine" do - context "When deploy is called, it" do - before(:each) do - @ctx = mock - @deploy_engine = Astute::DeploymentEngine.new(@ctx) - end - - it "should call valid method depends on attrs" do - nodes = [{'uid' => 1}] - attrs = {'deployment_mode' => 'ha_compute'} - attrs_modified = attrs.merge({'some' => 'somea'}) - - @deploy_engine.expects(:attrs_ha_compute).with(nodes, attrs).returns(attrs_modified) - @deploy_engine.expects(:deploy_ha_compute).with(nodes, attrs_modified) - # All implementations of deploy_piece go to subclasses - @deploy_engine.respond_to?(:deploy_piece).should be_false - @deploy_engine.deploy(nodes, attrs) - end - - it "should raise an exception if deployment mode is unsupported" do - nodes = [{'uid' => 1}] - attrs = {'deployment_mode' => 'unknown'} - expect {@deploy_engine.deploy(nodes, attrs)}.to raise_exception(/Method attrs_unknown is not implemented/) - end - end -end