[astute] Support of SimplePuppet in bin/astute, example provided
This commit is contained in:
parent
3bcc57d373
commit
ecdf8f6f19
@ -41,6 +41,15 @@ Astute.logger = Logger.new(STDOUT) if opts[:verbose]
|
|||||||
|
|
||||||
environment = YAML.load_file(opts[:filename])
|
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.deploy(reporter, environment['task_uuid'], environment['nodes'], environment['attributes'])
|
||||||
#orchestrator.verify_networks(reporter, task_id, nodes, networks)
|
#orchestrator.verify_networks(reporter, task_id, nodes, networks)
|
||||||
|
12
astute/examples/no_attrs.yaml
Normal file
12
astute/examples/no_attrs.yaml
Normal file
@ -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
|
@ -59,6 +59,8 @@ nodes:
|
|||||||
uid: devnailgun.mirantis.com
|
uid: devnailgun.mirantis.com
|
||||||
mac: 52:54:00:50:91:DD
|
mac: 52:54:00:50:91:DD
|
||||||
attributes:
|
attributes:
|
||||||
|
deployment_mode: multinode_compute
|
||||||
|
deployment_engine: nailyfact
|
||||||
glance:
|
glance:
|
||||||
db_password: glance
|
db_password: glance
|
||||||
user_password: glance
|
user_password: glance
|
||||||
|
@ -7,15 +7,17 @@ PUPPET_FADE_TIMEOUT = 60
|
|||||||
module Astute
|
module Astute
|
||||||
class DeploymentEngine
|
class DeploymentEngine
|
||||||
def initialize(context)
|
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
|
@ctx = context
|
||||||
end
|
end
|
||||||
|
|
||||||
def deploy(nodes, attrs)
|
def deploy(nodes, attrs)
|
||||||
|
# See implementation in subclasses, this may be everriden
|
||||||
attrs['deployment_mode'] ||= 'multinode_compute' # simple multinode deployment is the default
|
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']}"
|
||||||
Astute.logger.info "Deployment mode #{attrs['deployment_mode']}, using #{self.class} for deployment."
|
result = self.send("deploy_#{attrs['deployment_mode']}", nodes, attrs)
|
||||||
attrs_for_mode = self.send("attrs_#{attrs['deployment_mode']}", nodes, attrs)
|
|
||||||
result = self.send("deploy_#{attrs['deployment_mode']}", nodes, attrs_for_mode)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def method_missing(method, *args)
|
def method_missing(method, *args)
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
class Astute::DeploymentEngine::NailyFact < Astute::DeploymentEngine
|
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)
|
def create_facts(node, attrs)
|
||||||
metapublisher = Astute::Metadata.method(:publish_facts)
|
metapublisher = Astute::Metadata.method(:publish_facts)
|
||||||
# calculate_networks method is common and you can find it in superclass
|
# calculate_networks method is common and you can find it in superclass
|
||||||
|
@ -3,8 +3,8 @@ class Astute::DeploymentEngine::SimplePuppet < Astute::DeploymentEngine
|
|||||||
# with all required parameters for modules
|
# with all required parameters for modules
|
||||||
def deploy_piece(nodes, *args)
|
def deploy_piece(nodes, *args)
|
||||||
return false unless validate_nodes(nodes)
|
return false unless validate_nodes(nodes)
|
||||||
|
@ctx.reporter.report nodes_status(nodes, 'deploying')
|
||||||
Astute::PuppetdDeployer.deploy(@ctx, nodes)
|
Astute::PuppetdDeployer.deploy(@ctx, nodes)
|
||||||
@ctx.reporter.report nodes_status(nodes, 'ready')
|
|
||||||
nodes_roles = nodes.map { |n| { n['uid'] => n['role'] } }
|
nodes_roles = nodes.map { |n| { n['uid'] => n['role'] } }
|
||||||
Astute.logger.info "#{@ctx.task_id}: Finished deployment of nodes => roles: #{nodes_roles.inspect}"
|
Astute.logger.info "#{@ctx.task_id}: Finished deployment of nodes => roles: #{nodes_roles.inspect}"
|
||||||
end
|
end
|
||||||
|
@ -26,6 +26,7 @@ module Astute
|
|||||||
proxy_reporter = ProxyReporter.new(up_reporter)
|
proxy_reporter = ProxyReporter.new(up_reporter)
|
||||||
context = Context.new(task_id, proxy_reporter, @log_parser)
|
context = Context.new(task_id, proxy_reporter, @log_parser)
|
||||||
deploy_engine_instance = @deploy_engine.new(context)
|
deploy_engine_instance = @deploy_engine.new(context)
|
||||||
|
Astute.logger.info "Using #{deploy_engine_instance.class} for deployment."
|
||||||
deploy_engine_instance.deploy(nodes, attrs)
|
deploy_engine_instance.deploy(nodes, attrs)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user