From b3bcfb586ea2ae0343284401169119e0de63a4c8 Mon Sep 17 00:00:00 2001 From: Mike Scherbakov Date: Fri, 12 Oct 2012 16:53:49 +0400 Subject: [PATCH] [orchestrator] Started integration of network checker --- orchestrator/bin/orchestrator | 8 +++++- orchestrator/lib/orchestrator.rb | 1 + orchestrator/lib/orchestrator/deployer.rb | 3 -- orchestrator/lib/orchestrator/network.rb | 28 +++++++++++++++++++ orchestrator/lib/orchestrator/orchestrator.rb | 22 ++++----------- .../mcollective/agent/erase_node.rb | 0 orchestrator/mcollective/agent/net_probe.ddl | 27 ++++++++++++++++++ .../mcollective/agent/net_probe.rb | 9 +----- orchestrator/setup-env.sh | 1 + 9 files changed, 70 insertions(+), 29 deletions(-) create mode 100644 orchestrator/lib/orchestrator/network.rb rename {bootstrap/sync/usr/share/mcollective/plugins => orchestrator}/mcollective/agent/erase_node.rb (100%) create mode 100644 orchestrator/mcollective/agent/net_probe.ddl rename {bootstrap/sync/usr/share/mcollective/plugins => orchestrator}/mcollective/agent/net_probe.rb (89%) diff --git a/orchestrator/bin/orchestrator b/orchestrator/bin/orchestrator index 1bbc20a1d..7446eba13 100755 --- a/orchestrator/bin/orchestrator +++ b/orchestrator/bin/orchestrator @@ -11,7 +11,13 @@ end reporter = ConsoleReporter.new -nodes = [{'mac' => 'devnailgun.mirantis.com', 'role' => 'test_controller'}] +nodes = [{'id' => '1', 'ip' => '10.1.1.2', 'mac' => 'devnailgun.mirantis.com', 'role' => 'test_controller'}, + {'id' => '2', 'ip' => '10.1.1.3', 'mac' => 'mcoll2', 'role' => 'test_controller'}] + +networks = [{'id' => 1, 'vlan_id' => 100, 'cidr' => '10.0.0.0/24'}, + {'id' => 2, 'vlan_id' => 101, 'cidr' => '192.168.0.0/24'}] + task_id = `uuidgen`.strip orchestrator = Orchestrator::Orchestrator.new orchestrator.deploy(reporter, task_id, nodes) +#orchestrator.verify_networks(reporter, task_id, nodes, networks) diff --git a/orchestrator/lib/orchestrator.rb b/orchestrator/lib/orchestrator.rb index 3bd4aaecc..b87d481bc 100644 --- a/orchestrator/lib/orchestrator.rb +++ b/orchestrator/lib/orchestrator.rb @@ -7,6 +7,7 @@ require 'orchestrator/helpers' module Orchestrator autoload 'PuppetPollingDeployer', 'orchestrator/deployer' autoload 'FactsPublisher', 'orchestrator/metadata' + autoload 'Network', 'orchestrator/network' def self.logger @logger ||= Logger.new(STDOUT) diff --git a/orchestrator/lib/orchestrator/deployer.rb b/orchestrator/lib/orchestrator/deployer.rb index e1e9ed634..d20588f64 100644 --- a/orchestrator/lib/orchestrator/deployer.rb +++ b/orchestrator/lib/orchestrator/deployer.rb @@ -48,8 +48,6 @@ module Orchestrator self.check_mcollective_result(mc.runonce, task_id) - reporter.report({'progress' => 2}) - ::Orchestrator.logger.debug "Waiting for puppet to finish deploymen on all nodes (timeout = #{PUPPET_TIMEOUT} sec)..." time_before = Time.now Timeout::timeout(PUPPET_TIMEOUT) do # 30 min for deployment to be done @@ -61,7 +59,6 @@ module Orchestrator time_spent = Time.now - time_before ::Orchestrator.logger.info "Spent #{time_spent} seconds on puppet run for following nodes(macs): #{nodes.map {|n| n['mac']}.join(',')}" - reporter.report({'progress' => 100}) end end end diff --git a/orchestrator/lib/orchestrator/network.rb b/orchestrator/lib/orchestrator/network.rb new file mode 100644 index 000000000..11c01863e --- /dev/null +++ b/orchestrator/lib/orchestrator/network.rb @@ -0,0 +1,28 @@ +module Orchestrator + class Network + include MCollective::RPC + include ::Orchestrator + + def check_network(reporter, task_id, nodes, networks) + if nodes.length < 2 + ::Orchestrator.logger.info "#{task_id}: Network checker: at least two nodes are required to check network connectivity. Do nothing." + return false + end + macs = nodes.map {|n| n['mac'].gsub(":", "")} + # TODO Everything breakes if agent not found. We have to handle that + mc = rpcclient("net_probe") + mc.progress = false + mc.discover(:nodes => macs) + + stats = mc.start_frame_listeners(:iflist => ['eth0'].to_json) + check_mcollective_result(stats, task_id) + + # Interface is hardcoded for now. Later we expect it to be passed from Nailgun backend + stats = mc.send_probing_frames(:interfaces => {'eth0' => networks.map {|n| n['vlan_id']}.join(',')}.to_json) + check_mcollective_result(stats, task_id) + + stats = mc.get_probing_info + printrpc mc.get_probing_info + end + end +end diff --git a/orchestrator/lib/orchestrator/orchestrator.rb b/orchestrator/lib/orchestrator/orchestrator.rb index 1452e7641..720b23c85 100644 --- a/orchestrator/lib/orchestrator/orchestrator.rb +++ b/orchestrator/lib/orchestrator/orchestrator.rb @@ -6,6 +6,7 @@ module Orchestrator def initialize @deployer = PuppetPollingDeployer.new @metapublisher = FactsPublisher.new + @network = Network.new end def deploy(reporter, task_id, nodes) @@ -30,25 +31,12 @@ module Orchestrator ::Orchestrator.logger.info "#{task_id}: Starting deployment of other roles on nodes(macs): #{other_nodes.map {|n| n['mac']}.join(',')}" @metapublisher.post(reporter, task_id, other_nodes) @deployer.deploy(reporter, task_id, other_nodes) + reporter.report({'progress' => 100}) end - # TODO rewrite it in a new model - #def verify_networks(reporter, task_id, nodes, networks) - #macs = nodes.map {|n| n['mac'].gsub(":", "")} - #mc = rpcclient("net_probe") - #mc.progress = false - #mc.discover(:nodes => macs) - - #stats = mc.start_frame_listeners({'iflist' => 'eth0'}) - #check_mcollective_result(stats) - - #stats = mc.send_probing_frames({'interfaces' => {'eth0' => networks.map {|n| n['vlan_id']}.join(',')}}) - #check_mcollective_result(stats) - - #sleep 5 - #stats = mc.get_probing_info - #printrpc mc.get_probing_info - #end + def verify_networks(reporter, task_id, nodes, networks) + @network.check_network(reporter, task_id, nodes, networks) + end end end diff --git a/bootstrap/sync/usr/share/mcollective/plugins/mcollective/agent/erase_node.rb b/orchestrator/mcollective/agent/erase_node.rb similarity index 100% rename from bootstrap/sync/usr/share/mcollective/plugins/mcollective/agent/erase_node.rb rename to orchestrator/mcollective/agent/erase_node.rb diff --git a/orchestrator/mcollective/agent/net_probe.ddl b/orchestrator/mcollective/agent/net_probe.ddl new file mode 100644 index 000000000..92e13bea2 --- /dev/null +++ b/orchestrator/mcollective/agent/net_probe.ddl @@ -0,0 +1,27 @@ +metadata :name => "Network Probe Agent", + :description => "Check network connectivity between nodes.", + :author => "Andrey Danin", + :license => "MIT", + :version => "0.1", + :url => "http://mirantis.com", + :timeout => 60 + +action "start_frame_listeners", :description => "Starts catching packets on interfaces" do + display :always +end + +action "send_probing_frames", :description => "Sends packets with VLAN tags" do + display :always +end + +action "get_probing_info", :description => "Get info about packets catched" do + display :always +end + +action "stop_frame_listeners", :description => "Stop catching packets, dump data to file" do + display :always +end + +action "echo", :description => "Silly echo" do + display :always +end diff --git a/bootstrap/sync/usr/share/mcollective/plugins/mcollective/agent/net_probe.rb b/orchestrator/mcollective/agent/net_probe.rb similarity index 89% rename from bootstrap/sync/usr/share/mcollective/plugins/mcollective/agent/net_probe.rb rename to orchestrator/mcollective/agent/net_probe.rb index 2d50e5e5d..7f299baf0 100644 --- a/bootstrap/sync/usr/share/mcollective/plugins/mcollective/agent/net_probe.rb +++ b/orchestrator/mcollective/agent/net_probe.rb @@ -3,13 +3,6 @@ require "json" module MCollective module Agent class Net_probe "Network Probe Agent", - :description => "Check network connectivity between nodes.", - :author => "Andrey Danin", - :license => "MIT", - :version => "0.1", - :url => "http://mirantis.com", - :timeout => 60 uid = open('/etc/bootif').gets.chomp @@ -40,7 +33,7 @@ module MCollective end action "stop_frame_listeners" do - stop_frame_listeners + stop_frame_listeners end action "echo" do diff --git a/orchestrator/setup-env.sh b/orchestrator/setup-env.sh index 995ddb619..967084698 100755 --- a/orchestrator/setup-env.sh +++ b/orchestrator/setup-env.sh @@ -5,4 +5,5 @@ for agent in `ls mcollective/agent/`; do done ln -sfT `readlink -f puppet/modules/nailytest` /etc/puppet/modules/nailytest ln -sf `readlink -f puppet/manifests/site.pp` /etc/puppet/manifests/site.pp +uuidgen > /etc/bootif # for net_probe plugin service mcollective restart