def test_pool_recycle_with_pre_provision_cleanup_on_move_error(self, tsuru_pool_mock, stdout, stderr): fake_pool = FakeTsuruPool('foobar', move_node_containers_error=True) tsuru_pool_mock.return_value = fake_pool with self.assertRaises(MoveNodeContainersError): plugin.pool_recycle("foobar", pre_provision=True) self.assertEqual(['127.0.0.1', '10.10.1.1', '10.1.1.2', '9.10.11.12'], fake_pool.get_machines()) self.assertEqual(['10.10.1.1', '10.1.1.2', '9.10.11.12', '127.0.0.1'], fake_pool.get_nodes())
def test_pool_recycle_running_with_pre_provision(self, tsuru_pool_mock, stdout, stderr): tsuru_pool_mock.return_value = FakeTsuruPool('foobar') plugin.pool_recycle('foobar', pre_provision=True) call_stdout_list = [ call( 'Creating new node on pool "foobar" using templateA template\n' ), call( 'Creating new node on pool "foobar" using templateB template\n' ), call( 'Creating new node on pool "foobar" using templateA template\n' ), call('Using 9.10.11.12 node as destination node\n'), call('Removing node "127.0.0.1" from pool "foobar"\n'), call('Moving all containers from old node "127.0.0.1" to new node ' + '"9.10.11.12"\n'), call('Using 5.6.7.8 node as destination node\n'), call('Removing node "10.10.1.1" from pool "foobar"\n'), call( 'Moving all containers from old node "10.10.1.1" to new node "5.6.7.8"\n' ), call('Using 1.2.3.4 node as destination node\n'), call('Removing node "10.1.1.2" from pool "foobar"\n'), call( 'Moving all containers from old node "10.1.1.2" to new node "1.2.3.4"\n' ) ] self.assertEqual(stdout.write.mock_calls, call_stdout_list)
def test_pool_recycle_success_removing_node_from_iaas( self, tsuru_pool_mock, stdout): tsuru_pool_mock.return_value = FakeTsuruPool('foobar') plugin.pool_recycle('foobar', True) call_stdout_list = [ call( 'Creating new node on pool "foobar" using templateA template\n' ), call('Removing node "127.0.0.1" from pool "foobar"\n'), call( 'Moving all containers from old node "127.0.0.1" to new node "1.2.3.4"\n' ), call('Machine 127.0.0.1 removed from IaaS\n'), call( 'Creating new node on pool "foobar" using templateB template\n' ), call('Removing node "10.10.1.1" from pool "foobar"\n'), call('Moving all containers from old node "10.10.1.1" ' 'to new node "5.6.7.8"\n'), call('Machine 10.10.1.1 removed from IaaS\n'), call( 'Creating new node on pool "foobar" using templateA template\n' ), call('Removing node "10.1.1.2" from pool "foobar"\n'), call( 'Moving all containers from old node "10.1.1.2" to new node "9.10.11.12"\n' ), call('Machine 10.1.1.2 removed from IaaS\n') ] stdout.write.assert_has_calls(call_stdout_list)
def test_pool_recycle_success_removing_node_from_iaas( self, tsuru_pool_mock, stdout): tsuru_pool_mock.return_value = FakeTsuruPool('foobar') plugin.pool_recycle('foobar', True) call_stdout_list = [ call( 'Going to recycle 3 node(s) from pool "foobar" using 2 templates.\n' ), call( '(1/3) Creating new node on pool "foobar" using "templateA" template\n' ), call('Destroying node "127.0.0.1\n'), call('\n'), call( '(2/3) Creating new node on pool "foobar" using "templateB" template\n' ), call('Destroying node "10.10.1.1\n'), call('\n'), call( '(3/3) Creating new node on pool "foobar" using "templateA" template\n' ), call('Destroying node "10.1.1.2\n'), call('\n') ] stdout.write.assert_has_calls(call_stdout_list)
def test_pool_recycle_on_dry_mode(self, users, disable_healing, get_machines_templates, get_nodes, stdout): users.return_value = {"Email": "myuser"} disable_healing.return_value = disable_healing get_machines_templates.return_value = ['templateA', 'templateB', 'templateC'] get_nodes.return_value = ['http://127.0.0.1:4243', '10.10.2.2', '10.2.3.2', 'http://2.3.2.1:2123'] plugin.pool_recycle('foobar', True) call_stdout_list = [call('Going to recycle 4 node(s) from pool "foobar" using 3 templates.\n'), call('(1/4) Creating new node on pool "foobar" using "templateA" template\n'), call('Destroying node "http://127.0.0.1:4243\n'), call('\n'), call('(2/4) Creating new node on pool "foobar" using "templateB" template\n'), call('Destroying node "10.10.2.2\n'), call('\n'), call('(3/4) Creating new node on pool "foobar" using "templateC" template\n'), call('Destroying node "10.2.3.2\n'), call('\n'), call('(4/4) Creating new node on pool "foobar" using "templateA" template\n'), call('Destroying node "http://2.3.2.1:2123\n'), call('\n'), call('Done.\n')] self.assertEqual(stdout.write.call_args_list, call_stdout_list) self.assertEqual(2, disable_healing.call_count)
def test_pool_recycle_with_pre_provision_cleanup_on_node_create_error(self, tsuru_pool_mock, stdout, stderr): fake_pool = FakeTsuruPool('foobar', pre_provision_error=True, raise_errors_on_call_counter=1) tsuru_pool_mock.return_value = fake_pool with self.assertRaises(NewNodeError): plugin.pool_recycle("foobar", pre_provision=True) self.assertEqual(['127.0.0.1', '10.10.1.1', '10.1.1.2'], fake_pool.get_machines()) self.assertEqual(['127.0.0.1', '10.10.1.1', '10.1.1.2'], fake_pool.get_nodes())
def test_pool_recycle_with_pre_provision_with_remove_old_nodes( self, tsuru_pool_mock, stdout, stderr): fake_pool = FakeTsuruPool('foobar') tsuru_pool_mock.return_value = fake_pool plugin.pool_recycle("foobar", pre_provision=True, destroy_node=True) self.assertEqual(['1.2.3.4', '5.6.7.8', '9.10.11.12'], fake_pool.get_machines()) self.assertEqual(['9.10.11.12', '5.6.7.8', '1.2.3.4'], fake_pool.get_nodes())
def test_pool_recycle_with_pre_provision_cleanup_on_move_error( self, tsuru_pool_mock, stdout, stderr): fake_pool = FakeTsuruPool('foobar', move_node_containers_error=True) tsuru_pool_mock.return_value = fake_pool with self.assertRaises(MoveNodeContainersError): plugin.pool_recycle("foobar", pre_provision=True) self.assertEqual(['127.0.0.1', '10.10.1.1', '10.1.1.2', '9.10.11.12'], fake_pool.get_machines()) self.assertEqual(['10.10.1.1', '10.1.1.2', '9.10.11.12', '127.0.0.1'], fake_pool.get_nodes())
def test_pool_recycle_error_on_moving_containers(self, tsuru_pool_mock, stdout, stderr): tsuru_pool_mock.return_value = FakeTsuruPool('foobar', True) with self.assertRaises(MoveNodeContainersError) as move_exception: plugin.pool_recycle('foobar') call_stdout_list = [call('Creating new node on pool "foobar" using templateA template\n'), call('Removing node "127.0.0.1" from pool "foobar"\n'), call('Moving all containers from old node "127.0.0.1" to new node "1.2.3.4"\n')] exception_msg = move_exception.exception.message self.assertEqual(stdout.write.mock_calls, call_stdout_list) self.assertEqual(exception_msg, 'error moving 127.0.0.1 to 1.2.3.4')
def test_pool_recycle_with_pre_provision_cleanup_on_node_create_error( self, tsuru_pool_mock, stdout, stderr): fake_pool = FakeTsuruPool('foobar', pre_provision_error=True, raise_errors_on_call_counter=1) tsuru_pool_mock.return_value = fake_pool with self.assertRaises(NewNodeError): plugin.pool_recycle("foobar", pre_provision=True) self.assertEqual(['127.0.0.1', '10.10.1.1', '10.1.1.2'], fake_pool.get_machines()) self.assertEqual(['127.0.0.1', '10.10.1.1', '10.1.1.2'], fake_pool.get_nodes())
def test_pool_recycle_error_on_moving_containers(self, tsuru_pool_mock, stdout, stderr): tsuru_pool_mock.return_value = FakeTsuruPool('foobar', True) with self.assertRaises(MoveNodeContainersError) as move_exception: plugin.pool_recycle('foobar') call_stdout_list = [ call( 'Creating new node on pool "foobar" using templateA template\n' ), call('Removing node "127.0.0.1" from pool "foobar"\n'), call( 'Moving all containers from old node "127.0.0.1" to new node "1.2.3.4"\n' ) ] exception_msg = move_exception.exception.message self.assertEqual(stdout.write.mock_calls, call_stdout_list) self.assertEqual(exception_msg, 'error moving 127.0.0.1 to 1.2.3.4')
def test_pool_recycle_running_with_pre_provision(self, tsuru_pool_mock, stdout, stderr): tsuru_pool_mock.return_value = FakeTsuruPool('foobar') plugin.pool_recycle('foobar', pre_provision=True) call_stdout_list = [call('Creating new node on pool "foobar" using templateA template\n'), call('Creating new node on pool "foobar" using templateB template\n'), call('Creating new node on pool "foobar" using templateA template\n'), call('Using 9.10.11.12 node as destination node\n'), call('Removing node "127.0.0.1" from pool "foobar"\n'), call('Moving all containers from old node "127.0.0.1" to new node ' + '"9.10.11.12"\n'), call('Using 5.6.7.8 node as destination node\n'), call('Removing node "10.10.1.1" from pool "foobar"\n'), call('Moving all containers from old node "10.10.1.1" to new node "5.6.7.8"\n'), call('Using 1.2.3.4 node as destination node\n'), call('Removing node "10.1.1.2" from pool "foobar"\n'), call('Moving all containers from old node "10.1.1.2" to new node "1.2.3.4"\n')] self.assertEqual(stdout.write.mock_calls, call_stdout_list)
def test_pool_recycle_success_removing_node_from_iaas(self, tsuru_pool_mock, stdout): tsuru_pool_mock.return_value = FakeTsuruPool('foobar') plugin.pool_recycle('foobar', True) call_stdout_list = [call('Creating new node on pool "foobar" using templateA template\n'), call('Removing node "127.0.0.1" from pool "foobar"\n'), call('Moving all containers from old node "127.0.0.1" to new node "1.2.3.4"\n'), call('Machine 127.0.0.1 removed from IaaS\n'), call('Creating new node on pool "foobar" using templateB template\n'), call('Removing node "10.10.1.1" from pool "foobar"\n'), call('Moving all containers from old node "10.10.1.1" ' 'to new node "5.6.7.8"\n'), call('Machine 10.10.1.1 removed from IaaS\n'), call('Creating new node on pool "foobar" using templateA template\n'), call('Removing node "10.1.1.2" from pool "foobar"\n'), call('Moving all containers from old node "10.1.1.2" to new node "9.10.11.12"\n'), call('Machine 10.1.1.2 removed from IaaS\n')] stdout.write.assert_has_calls(call_stdout_list)
def test_pool_recycle_on_dry_mode(self, get_machines_templates, get_nodes, stdout): get_machines_templates.return_value = [ 'templateA', 'templateB', 'templateC' ] get_nodes.return_value = [ 'http://127.0.0.1:4243', '10.10.2.2', '10.2.3.2', 'http://2.3.2.1:2123' ] plugin.pool_recycle('foobar', False, True) call_stdout_list = [ call( 'Creating new node on pool "foobar" using "templateA" template\n' ), call('Removing node "http://127.0.0.1:4243" from pool "foobar"\n'), call( 'Moving all containers on old node "http://127.0.0.1:4243" to new node\n' ), call('\n'), call( 'Creating new node on pool "foobar" using "templateB" template\n' ), call('Removing node "10.10.2.2" from pool "foobar"\n'), call( 'Moving all containers on old node "10.10.2.2" to new node\n'), call('\n'), call( 'Creating new node on pool "foobar" using "templateC" template\n' ), call('Removing node "10.2.3.2" from pool "foobar"\n'), call('Moving all containers on old node "10.2.3.2" to new node\n'), call('\n'), call( 'Creating new node on pool "foobar" using "templateA" template\n' ), call('Removing node "http://2.3.2.1:2123" from pool "foobar"\n'), call( 'Moving all containers on old node "http://2.3.2.1:2123" to new node\n' ), call('\n') ] self.assertEqual(stdout.write.call_args_list, call_stdout_list)
def test_pool_recycle_on_dry_mode(self, get_machines_templates, get_nodes, stdout): get_machines_templates.return_value = ['templateA', 'templateB', 'templateC'] get_nodes.return_value = ['http://127.0.0.1:4243', '10.10.2.2', '10.2.3.2', 'http://2.3.2.1:2123'] plugin.pool_recycle('foobar', False, True) call_stdout_list = [call('Creating new node on pool "foobar" using "templateA" template\n'), call('Removing node "http://127.0.0.1:4243" from pool "foobar"\n'), call('Moving all containers on old node "http://127.0.0.1:4243" to new node\n'), call('\n'), call('Creating new node on pool "foobar" using "templateB" template\n'), call('Removing node "10.10.2.2" from pool "foobar"\n'), call('Moving all containers on old node "10.10.2.2" to new node\n'), call('\n'), call('Creating new node on pool "foobar" using "templateC" template\n'), call('Removing node "10.2.3.2" from pool "foobar"\n'), call('Moving all containers on old node "10.2.3.2" to new node\n'), call('\n'), call('Creating new node on pool "foobar" using "templateA" template\n'), call('Removing node "http://2.3.2.1:2123" from pool "foobar"\n'), call('Moving all containers on old node "http://2.3.2.1:2123" to new node\n'), call('\n')] self.assertEqual(stdout.write.call_args_list, call_stdout_list)
def test_pool_recycle_with_pre_provision_with_remove_old_nodes(self, tsuru_pool_mock, stdout, stderr): fake_pool = FakeTsuruPool('foobar') tsuru_pool_mock.return_value = fake_pool plugin.pool_recycle("foobar", pre_provision=True, destroy_node=True) self.assertEqual(['1.2.3.4', '5.6.7.8', '9.10.11.12'], fake_pool.get_machines()) self.assertEqual(['9.10.11.12', '5.6.7.8', '1.2.3.4'], fake_pool.get_nodes())