コード例 #1
0
    def test_as_library(self):

        engine = PlumberyEngine(myEuropeanPlan, myAmericanBinding)
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        engine.set_shared_secret('fake_secret')
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')

        facilities = engine.list_facility('NA9')
        self.assertEqual(len(facilities), 1)

        facility = facilities[0]
        self.assertEqual(facility.get_setting('regionId'), 'dd-na')
        self.assertEqual(facility.get_setting('locationId'), 'NA9')

        self.assertTrue(facility.get_blueprint('fake') is None)

        blueprint = facility.get_blueprint('myBlueprint')

        node = blueprint['nodes'][0]
        self.assertEqual(list(node)[0], 'toto')

        config = node['toto']['cloud-config']
        self.assertEqual(config['hostname'], 'toto')
        self.assertEqual(config['write_files'][0]['content'].count('toto'), 6)

        engine.do('deploy')
        engine.do('dispose')
コード例 #2
0
class BackupConfigurationTests(unittest.TestCase):
    def setUp(self):
        self.plumbery = PlumberyEngine()
        self.plumbery.set_user_name('fake_user')
        self.plumbery.set_user_password('fake_password')
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.plumbery.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)
        self.facility = PlumberyFacility(
            plumbery=self.plumbery, fittings=myFacility)
        self.facility.power_on()

    def test_backup_validation_valid(self):
        settings = {
            'backup': 'essentials'
        }
        config = backup.BackupConfiguration(engine=None, facility=None)
        self.assertTrue(config.validate(settings))

    def test_backup_validation_invalid(self):
        settings = {
            'backup': 'potato'
        }
        config = backup.BackupConfiguration(engine=None, facility=None)
        with self.assertRaises(ConfigurationError):
            config.validate(settings)

    def test_backup_configuration(self):
        settings = {
            'backup': 'essentials',
        }
        config = backup.BackupConfiguration(self.plumbery, self.facility)
        backupConfiguration = config.configure(TestNode(), settings)
        self.assertTrue(backupConfiguration)
コード例 #3
0
ファイル: test_engine.py プロジェクト: Mil4dy/plumbery
    def test_as_library(self):

        engine = PlumberyEngine(myFacility)
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        engine.set_shared_secret('fake_secret')
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')

        facilities = engine.list_facility('NA9')
        self.assertEqual(len(facilities), 1)

        facility = facilities[0]
        self.assertEqual(facility.get_setting('regionId'), 'dd-na')
        self.assertEqual(facility.get_setting('locationId'), 'NA9')

        blueprint = facility.get_blueprint('fake')
        self.assertEqual(blueprint.keys(),
                         ['ethernet', 'domain', 'nodes', 'target'])

        engine.do('deploy')
        engine.do('refresh')
        engine.do('dispose')
コード例 #4
0
ファイル: test_engine.py プロジェクト: Mil4dy/plumbery
    def test_set(self):

        settings = {
            'safeMode': False,
            'polishers': [
                {'ansible': {}},
                {'spit': {}},
                ]
            }

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        engine.set_shared_secret('fake_secret')
        self.assertEqual(engine.get_shared_secret(), 'fake_secret')

        random = engine.get_secret('random')
        self.assertEqual(len(random), 9)
        self.assertEqual(engine.get_secret('random'), random)

        engine.set_user_name('fake_name')
        self.assertEqual(engine.get_user_name(), 'fake_name')

        engine.set_user_password('fake_password')
        self.assertEqual(engine.get_user_password(), 'fake_password')

        engine.set(settings)
        self.assertEqual(engine.safeMode, False)

        engine.add_facility(myFacility)
        self.assertEqual(len(engine.facilities), 1)
コード例 #5
0
ファイル: test_engine.py プロジェクト: bernard357/plumbery
    def test_as_library(self):

        engine = PlumberyEngine(myEuropeanPlan, myAmericanBinding)
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        engine.set_shared_secret('fake_secret')
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')

        facilities = engine.list_facility('NA9')
        self.assertEqual(len(facilities), 1)

        facility = facilities[0]
        self.assertEqual(facility.get_setting('regionId'), 'dd-na')
        self.assertEqual(facility.get_setting('locationId'), 'NA9')

        self.assertTrue(facility.get_blueprint('fake') is None)

        blueprint = facility.get_blueprint('myBlueprint')

        node = blueprint['nodes'][0]
        self.assertEqual(list(node)[0], 'toto')

        config = node['toto']['cloud-config']
        self.assertEqual(config['hostname'], 'toto')
        self.assertEqual(config['write_files'][0]['content'].count('toto'), 6)

        engine.do('deploy')
        engine.do('dispose')
コード例 #6
0
ファイル: test_engine.py プロジェクト: bernard357/plumbery
    def test_set(self):

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        file = os.path.abspath(
            os.path.dirname(__file__))+'/fixtures/dummy_rsa.pub'

        settings = {
            'keys': [ "*hello-there*" ],
            }

        with self.assertRaises(ValueError):
            engine.set_settings(settings)

        settings = {
            'keys': [ file ],
            }

        engine.set_settings(settings)
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertTrue(file in engine.get_shared_key_files())

        settings = {
            'safeMode': False,
            'polishers': [
                {'ansible': {}},
                {'configure': {}},
                ],
            'keys': [ file, file ],
            }

        engine.set_settings(settings)
        self.assertEqual(engine.safeMode, False)
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertTrue(file in engine.get_shared_key_files())

        engine.add_facility(myFacility)
        self.assertEqual(len(engine.facilities), 1)

        self.assertEqual(engine.get_shared_user(), 'root')
        engine.set_shared_user('ubuntu')
        self.assertEqual(engine.get_shared_user(), 'ubuntu')

        engine.set_shared_secret('fake_secret')
        self.assertEqual(engine.get_shared_secret(), 'fake_secret')

        random = engine.get_secret('random')
        self.assertEqual(len(random), 9)
        self.assertEqual(engine.get_secret('random'), random)

        engine.set_user_name('fake_name')
        self.assertEqual(engine.get_user_name(), 'fake_name')

        engine.set_user_password('fake_password')
        self.assertEqual(engine.get_user_password(), 'fake_password')
コード例 #7
0
 def test_settings_private(self):
     engine = PlumberyEngine()
     engine.set_shared_secret('fake_secret')
     engine.set_user_name('fake_name')
     engine.set_user_password('fake_password')
     engine.set_fittings(myPrivatePlan)
     facilities = engine.list_facility('quasimoto.com')
     self.assertEqual(len(facilities), 1)
     facilities[0].power_on()
コード例 #8
0
ファイル: test_engine.py プロジェクト: bernard357/plumbery
 def test_settings_private(self):
     engine = PlumberyEngine()
     engine.set_shared_secret('fake_secret')
     engine.set_user_name('fake_name')
     engine.set_user_password('fake_password')
     engine.set_fittings(myPrivatePlan)
     facilities = engine.list_facility('quasimoto.com')
     self.assertEqual(len(facilities), 1)
     facilities[0].power_on()
コード例 #9
0
ファイル: test_engine.py プロジェクト: bernard357/plumbery
    def test_lifecycle(self):

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        engine.set_shared_secret('fake_secret')
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')

        engine.do('build')
        engine.build_all_blueprints()
        engine.do('build', 'myBlueprint')
        engine.build_blueprint('myBlueprint')

        engine.do('deploy')
        engine.do('deploy', 'myBlueprint')

        engine.do('destroy')
        engine.destroy_all_blueprints()
        engine.do('destroy', 'myBlueprint')
        engine.destroy_blueprint('myBlueprint')

        engine.do('dispose')
        engine.do('dispose', 'myBlueprint')

        engine.do('polish')
        engine.polish_all_blueprints()
        engine.do('polish', 'myBlueprint')
        engine.polish_blueprint('myBlueprint')

        engine.do('refresh')
        engine.do('refresh', 'myBlueprint')

        engine.do('secrets')

        engine.do('start')
        engine.start_all_blueprints()
        engine.do('start', 'myBlueprint')
        engine.start_blueprint('myBlueprint')

        engine.do('stop')
        engine.stop_all_blueprints()
        engine.do('stop', 'myBlueprint')
        engine.stop_blueprint('myBlueprint')

        engine.do('wipe')
        engine.wipe_all_blueprints()
        engine.do('wipe', 'myBlueprint')
        engine.wipe_blueprint('myBlueprint')

        banner = engine.document_elapsed()
        self.assertEqual('Worked for you' in banner, True)
コード例 #10
0
ファイル: test_engine.py プロジェクト: hgolla-repos/plumbery
    def test_lifecycle(self):

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        engine.set_shared_secret('fake_secret')
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')

        engine.do('build')
        engine.build_all_blueprints()
        engine.do('build', 'myBlueprint')
        engine.build_blueprint('myBlueprint')

        engine.do('deploy')
        engine.do('deploy', 'myBlueprint')

        engine.do('destroy')
        engine.destroy_all_blueprints()
        engine.do('destroy', 'myBlueprint')
        engine.destroy_blueprint('myBlueprint')

        engine.do('dispose')
        engine.do('dispose', 'myBlueprint')

        engine.do('polish')
        engine.polish_all_blueprints()
        engine.do('polish', 'myBlueprint')
        engine.polish_blueprint('myBlueprint')

        engine.do('refresh')
        engine.do('refresh', 'myBlueprint')

        engine.do('secrets')

        engine.do('start')
        engine.start_all_blueprints()
        engine.do('start', 'myBlueprint')
        engine.start_blueprint('myBlueprint')

        engine.do('stop')
        engine.stop_all_blueprints()
        engine.do('stop', 'myBlueprint')
        engine.stop_blueprint('myBlueprint')

        engine.do('wipe')
        engine.wipe_all_blueprints()
        engine.do('wipe', 'myBlueprint')
        engine.wipe_blueprint('myBlueprint')

        banner = engine.document_elapsed()
        self.assertEqual('Worked for you' in banner, True)
コード例 #11
0
    def test_settings_private(self):
        settings = {
            'apiHost': 'smee.com',
            'locationId': 'NA5',
            'safeMode': True
        }
        engine = PlumberyEngine(plan=settings)
        engine.set_user_name('smee')
        engine.set_user_password('smee')
        facility = engine.list_facility()[0]
#        facility.power_on()
        self.assertEqual(facility.get_setting('locationId'), 'NA5')
        self.assertIsNone(facility.get_setting('regionId'))
コード例 #12
0
ファイル: test_facility.py プロジェクト: bernard357/plumbery
    def test_settings_private(self):
        settings = {
            'apiHost': 'smee.com',
            'locationId': 'NA5',
            'safeMode': True
        }
        engine = PlumberyEngine(plan=settings)
        engine.set_user_name('smee')
        engine.set_user_password('smee')
        facility = engine.list_facility()[0]
#        facility.power_on()
        self.assertEqual(facility.get_setting('locationId'), 'NA5')
        self.assertIsNone(facility.get_setting('regionId'))
コード例 #13
0
 def test_main(self):
     engine = PlumberyEngine()
     engine.from_text(myPlan)
     engine.set_user_name('fake_name')
     engine.set_user_password('fake_password')
     with self.assertRaises(SystemExit):
         main(['bad args'], engine)
     with self.assertRaises(SystemExit):
         main(['fittings.yaml'], engine)
     with self.assertRaises(SystemExit):
         main(['fittings.yaml', 'xyz123', 'web'], engine)
     with self.assertRaises(SystemExit):
         main(['-v'], engine)
     with self.assertRaises(SystemExit):
         main(['fittings.yaml', 'build', 'web', '-v'], engine)
コード例 #14
0
    def test_engine(self):

        engine = PlumberyEngine()
        context = PlumberyContext(context=engine)

        template = "we are running plumbery {{ plumbery.version }}"
        expected = "we are running plumbery " + __version__
        self.assertEqual(self.text.expand_string(template, context), expected)

        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')

        template = "{{ name.credentials }} {{ password.credentials }}"
        expected = engine.get_user_name() + " " + engine.get_user_password()
        self.assertEqual(self.text.expand_string(template, context), expected)
コード例 #15
0
ファイル: test_engine.py プロジェクト: asimkhawaja/plumbery
    def test_main(self):

        engine = PlumberyEngine()
        engine.set_fittings(myPlan)
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')
        with self.assertRaises(SystemExit):
            main(['bad args'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml', 'xyz123', 'web'], engine)
        with self.assertRaises(SystemExit):
            main(['-v'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml', 'build', 'web', '-v'], engine)
コード例 #16
0
    def test_engine(self):

        engine = PlumberyEngine()
        context = PlumberyContext(context=engine)

        template = "we are running plumbery {{ plumbery.version }}"
        expected = "we are running plumbery "+__version__
        self.assertEqual(
            self.text.expand_string(template, context), expected)

        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')

        template = "{{ name.credentials }} {{ password.credentials }}"
        expected = engine.get_user_name()+" "+engine.get_user_password()
        self.assertEqual(
            self.text.expand_string(template, context), expected)
コード例 #17
0
ファイル: test_engine.py プロジェクト: bernard357/plumbery
    def test_main(self):

        with self.assertRaises(SystemExit):
            main(['fittings.yaml', 'build', 'web', '@EU6'])

        engine = PlumberyEngine()
        engine.set_fittings(myPlan)
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')
        with self.assertRaises(SystemExit):
            main(['-v'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml', 'build', 'web'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml', 'build', 'web', '-v'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml', 'build', 'web', '@EU6'], engine)
コード例 #18
0
class TestPlumberyFacility(unittest.TestCase):
    def setUp(self):
        self.plumbery = PlumberyEngine()
        self.plumbery.set_user_name('fake_user')
        self.plumbery.set_user_password('fake_password')
        self.fittings = PlumberyFittings(**fakeFittings)
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.facility = PlumberyFacility(plumbery=self.plumbery,
                                         fittings=self.fittings)
        self.facility.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

    def tearDown(self):
        self.facility = None

    def test_build_all_blueprints(self):
        self.facility.build_all_blueprints()

    def test_build_blueprint(self):
        self.facility.build_blueprint('fake')

    def test_destroy_all_nodes(self):
        self.facility.destroy_all_nodes()

    def test_destroy_nodes(self):
        self.facility.destroy_nodes('fake')

    def test_focus(self):
        self.facility.focus()

    def test_get_blueprint(self):
        self.facility.get_blueprint('fake')

    def test_start_all_nodes(self):
        self.facility.start_all_nodes()

    def test_start_nodes(self):
        self.facility.start_nodes('fake')

    def test_stop_all_nodes(self):
        self.facility.stop_all_nodes()

    def test_stop_nodes(self):
        self.facility.stop_nodes('fake')
コード例 #19
0
    def test_process_blueprint(self):

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        engine.set_shared_secret('fake_secret')
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')
        engine.set_fittings(myPrivatePlan)

        engine.process_blueprint(action='dummy', names='fake')

        action = FakeAction({})
        engine.process_blueprint(action, names='fake')
        self.assertEqual(action.count, 205)
コード例 #20
0
ファイル: test_engine.py プロジェクト: bernard357/plumbery
    def test_process_blueprint(self):

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        engine.set_shared_secret('fake_secret')
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')
        engine.set_fittings(myPrivatePlan)

        engine.process_blueprint(action='noop', names='fake')

        action = FakeAction({})
        engine.process_blueprint(action, names='fake')
        self.assertEqual(action.count, 205)
コード例 #21
0
ファイル: test_polisher.py プロジェクト: asimkhawaja/plumbery
def do_polish(polisher):

    engine = PlumberyEngine(myInformation)
    engine.set_shared_secret('fake_secret')
    engine.set_user_name('fake_name')
    engine.set_user_password('fake_password')

    polisher.go(engine)

    facility = engine.list_facility('NA9')[0]
    DimensionDataNodeDriver.connectionCls.conn_classes = (
        None, DimensionDataMockHttp)
    DimensionDataMockHttp.type = None
    facility.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

    polisher.move_to(facility)

    blueprint = facility.get_blueprint('test')
    infrastructure = PlumberyInfrastructure(facility)
    container = infrastructure.get_container(blueprint)

    polisher.shine_container(container)

    nodes = PlumberyNodes(facility)

    node = nodes.get_node('stackstorm')
    polisher.shine_node(node=node,
                        settings=fakeNodeSettings,
                        container=container)

    node = nodes.get_node('node1')
    polisher.shine_node(node=node,
                        settings=fakeNodeSettings,
                        container=container)

    polisher.move_to(FakeFacility())

    polisher.shine_container(FakeContainer())

    polisher.shine_node(node=FakeNode(),
                        settings=fakeNodeSettings,
                        container=FakeContainer())

    polisher.reap()
コード例 #22
0
ファイル: test_facility.py プロジェクト: fxcasadei/plumbery
class TestPlumberyFacility(unittest.TestCase):

    def setUp(self):
        self.plumbery = PlumberyEngine()
        self.plumbery.set_user_name('fake_user')
        self.plumbery.set_user_password('fake_password')
        self.fittings = PlumberyFittings(**fakeFittings)
        self.facility = PlumberyFacility(plumbery=self.plumbery, fittings=self.fittings)
        self.facility.region = FakeRegion()

    def tearDown(self):
        self.facility = None

    def test_build_all_blueprints(self):
        self.facility.build_all_blueprints()

    def test_build_blueprint(self):
        self.facility.build_blueprint('fake')

    def test_destroy_all_nodes(self):
        self.facility.destroy_all_nodes()

    def test_destroy_nodes(self):
        self.facility.destroy_nodes('fake')

    def test_focus(self):
        self.facility.focus()

    def test_get_blueprint(self):
        self.facility.get_blueprint('fake')

    def test_start_all_nodes(self):
        self.facility.start_all_nodes()

    def test_start_nodes(self):
        self.facility.start_nodes('fake')

    def test_stop_all_nodes(self):
        self.facility.stop_all_nodes()

    def test_stop_nodes(self):
        self.facility.stop_nodes('fake')
コード例 #23
0
ファイル: test_polisher.py プロジェクト: Mil4dy/plumbery
def do_polish(polisher):

    engine = PlumberyEngine()
    engine.set_shared_secret('fake_secret')
    engine.set_user_name('fake_name')
    engine.set_user_password('fake_password')
    engine.from_text(myInformation)

    polisher.go(engine)

    facility = engine.list_facility('NA9')[0]
    DimensionDataNodeDriver.connectionCls.conn_classes = (
        None, DimensionDataMockHttp)
    DimensionDataMockHttp.type = None
    facility.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

    polisher.move_to(facility)

    blueprint = facility.get_blueprint('test')
    infrastructure = PlumberyInfrastructure(facility)
    container = infrastructure.get_container(blueprint)

    polisher.shine_container(container)

    nodes = PlumberyNodes(facility)

    node = nodes.get_node('stackstorm')
    polisher.shine_node(
        node=node, settings=fakeNodeSettings, container=container)

    node = nodes.get_node('node1')
    polisher.shine_node(
        node=node, settings=fakeNodeSettings, container=container)

    polisher.move_to(FakeFacility())

    polisher.shine_container(FakeContainer())

    polisher.shine_node(
        node=FakeNode(), settings=fakeNodeSettings, container=FakeContainer())

    polisher.reap()
コード例 #24
0
    def test_set(self):

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        settings = {
            'safeMode': False,
            'polishers': [
                {
                    'ansible': {}
                },
                {
                    'configure': {}
                },
            ]
        }

        engine.set_settings(settings)
        self.assertEqual(engine.safeMode, False)

        engine.add_facility(myFacility)
        self.assertEqual(len(engine.facilities), 1)

        self.assertEqual(engine.get_shared_user(), 'root')
        engine.set_shared_user('ubuntu')
        self.assertEqual(engine.get_shared_user(), 'ubuntu')

        engine.set_shared_secret('fake_secret')
        self.assertEqual(engine.get_shared_secret(), 'fake_secret')

        random = engine.get_secret('random')
        self.assertEqual(len(random), 9)
        self.assertEqual(engine.get_secret('random'), random)

        engine.set_user_name('fake_name')
        self.assertEqual(engine.get_user_name(), 'fake_name')

        engine.set_user_password('fake_password')
        self.assertEqual(engine.get_user_password(), 'fake_password')
コード例 #25
0
ファイル: test_facility.py プロジェクト: bernard357/plumbery
class TestPlumberyFacility(unittest.TestCase):

    def setUp(self):
        self.plumbery = PlumberyEngine()
        self.plumbery.set_user_name('fake_user')
        self.plumbery.set_user_password('fake_password')
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.plumbery.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)
        self.facility = PlumberyFacility(
            plumbery=self.plumbery, fittings=fakeFittings)
        self.facility.power_on()

    def tearDown(self):
        self.facility = None

    def test_get_location_id(self):
        self.assertEqual(self.facility.get_location_id(), 'NA9')

    def test_list_basement(self):
        self.assertEqual(self.facility.list_basement(), ['fake1'])

    def test_list_blueprints(self):
        self.assertEqual(self.facility.list_blueprints(), ['fake1', 'fake2'])

    def test_expand_blueprint(self):
        self.assertEqual(
            self.facility.expand_blueprint('fake1'), ['fake1'])
        self.assertEqual(
            self.facility.expand_blueprint('fake1 unknown fake'), ['fake1'])
        self.assertEqual(
            self.facility.expand_blueprint('macro'), ['fake2'])
        self.assertEqual(
            self.facility.expand_blueprint('basement'), ['fake1'])

    def test_get_blueprint(self):
        self.assertEqual(
            self.facility.get_blueprint('fake2')['target'], 'fake2')
        self.assertIsNone(self.facility.get_blueprint('macro'))
        self.assertIsNone(self.facility.get_blueprint('crazyAndunknown'))

    def test_list_domains(self):
        self.assertEqual(self.facility.list_domains(), ['VDC1'])

    def test_list_ethernets(self):
        self.assertEqual(self.facility.list_ethernets(), ['vlan1'])

    def test_list_nodes(self):
        self.assertEqual(self.facility.list_nodes(),
                         ['stackstorm1', 'stackstorm2'])

    def test_get_image(self):
        self.assertRegexpMatches(
            self.facility.get_image().name, "^RedHat ")
        self.assertIsNone(self.facility.get_image('perfectlyUnknown'))

    def test_focus(self):
        self.facility.focus()

    def test_process_all_blueprints(self):
        action = FakeAction({})
        self.facility.process_all_blueprints(action)
        self.assertEqual(action.count, 14)

    def test_process_blueprint(self):
        action = FakeAction({})
        self.facility.process_blueprint(action, names='fake')
        self.assertEqual(action.count, 4)

    def test_build_all_blueprints(self):
        self.facility.build_all_blueprints()

    def test_build_blueprint(self):
        self.facility.build_blueprint('fake')

    def test_start_all_blueprints(self):
        self.facility.start_all_blueprints()

    def test_start_blueprint(self):
        self.facility.start_blueprint('fake')

    def test_polish_all_blueprints(self):
        self.facility.polish_all_blueprints(polishers='ping')

    def test_polish_blueprint(self):
        self.facility.polish_blueprint(names='fake', polishers='ping')

    def test_stop_all_blueprints(self):
        self.facility.stop_all_blueprints()

    def test_stop_blueprint(self):
        self.facility.stop_blueprint('fake')

    def test_wipe_all_blueprints(self):
        self.facility.wipe_all_blueprints()

    def test_wipe_blueprint(self):
        self.facility.wipe_blueprint('fake')

    def test_destroy_all_blueprints(self):
        self.facility.destroy_all_blueprints()

    def test_destroy_blueprint(self):
        self.facility.destroy_blueprint('fake')

    def test_lookup(self):
        self.assertEqual(self.facility.lookup('location.country'), 'US')
        self.assertEqual(self.facility.lookup('location.id'), 'NA9')
        self.assertEqual(self.facility.lookup('*unknown*'), None)

    def test_settings(self):
        engine = PlumberyEngine(defaultsPlan)
        facility = engine.list_facility('EU6')[0]
        self.assertEqual(facility.get_setting('locationId'), 'EU6')
        self.assertEqual(facility.get_setting('regionId'), 'dd-eu')
        self.assertEqual(facility.get_setting('prepare'), None)
        self.assertEqual(facility.get_setting('basement'), 'myBlueprint')

    def test_settings_private(self):
        settings = {
            'apiHost': 'smee.com',
            'locationId': 'NA5',
            'safeMode': True
        }
        engine = PlumberyEngine(plan=settings)
        engine.set_user_name('smee')
        engine.set_user_password('smee')
        facility = engine.list_facility()[0]
#        facility.power_on()
        self.assertEqual(facility.get_setting('locationId'), 'NA5')
        self.assertIsNone(facility.get_setting('regionId'))

    def test_blueprints(self):
        engine = PlumberyEngine(defaultsPlan)
        facility = engine.list_facility('EU6')[0]
        blueprint = facility.get_blueprint('myBlueprint')
        self.assertEqual(isinstance(blueprint, dict), True)
        self.assertEqual(blueprint['domain']['name'], 'myDC')
        self.assertEqual(blueprint['domain']['ipv4'], 'auto')
        self.assertEqual(blueprint['ethernet']['name'], 'myVLAN')
        self.assertEqual(blueprint['ethernet']['subnet'], '10.1.10.0')
        self.assertEqual(len(blueprint['ethernet']['accept']), 1)
        label = list(blueprint['nodes'][0])[0]
        node = blueprint['nodes'][0][label]
        self.assertEqual('default' not in node, True)
        self.assertEqual(node['cpu'], 3)
        self.assertEqual(node['memory'], 5)
        self.assertEqual(len(node['information']), 2)
        config = node['cloud-config']
        self.assertEqual(isinstance(config, dict), True)
        self.assertEqual(config['disable_root'], True)
        self.assertEqual(config['ssh_pwauth'], True)
        self.assertEqual(len(config['packages']), 4)
        self.assertEqual(len(config['runcmd']), 4)
コード例 #26
0
ファイル: test_engine.py プロジェクト: tonybaloney/plumbery
class TestPlumberyEngine(unittest.TestCase):

    def test_set(self):

        settings = {
            'safeMode': False,
            'polishers': [
                {'ansible': {}},
                {'spit': {}},
                ]
            }

        self.engine = PlumberyEngine()
        self.engine.set_shared_secret('fake_secret')
        self.assertEqual(self.engine.get_shared_secret(), 'fake_secret')

        random = self.engine.get_random_secret()
        self.assertEqual(len(random), 9)
        self.assertEqual(self.engine.get_random_secret(), random)

        self.engine.set_user_name('fake_name')
        self.assertEqual(self.engine.get_user_name(), 'fake_name')

        self.engine.set_user_password('fake_password')
        self.assertEqual(self.engine.get_user_password(), 'fake_password')

        self.engine.set(settings)
        self.assertEqual(self.engine.safeMode, False)

        try:
            self.engine.from_text(myPlan)
            self.engine.add_facility(myFacility)
            self.assertEqual(len(self.engine.facilities), 2)

        except socket.gaierror:
            pass
        except InvalidCredsError:
            pass

    def test_lifecycle(self):

        self.engine = PlumberyEngine()
        self.engine.set_shared_secret('fake_secret')
        self.assertEqual(self.engine.get_shared_secret(), 'fake_secret')

        self.engine.set_user_name('fake_name')
        self.assertEqual(self.engine.get_user_name(), 'fake_name')

        self.engine.set_user_password('fake_password')
        self.assertEqual(self.engine.get_user_password(), 'fake_password')

        try:
            self.engine.do('build')
            self.engine.build_all_blueprints()
            self.engine.build_blueprint('myBlueprint')

            self.engine.do('start')
            self.engine.start_all_blueprints()
            self.engine.start_blueprint('myBlueprint')

            self.engine.do('polish')
            self.engine.polish_all_blueprints()
            self.engine.polish_blueprint('myBlueprint')

            self.engine.do('stop')
            self.engine.stop_all_blueprints()
            self.engine.stop_blueprint('myBlueprint')

            self.engine.wipe_all_blueprints()
            self.engine.wipe_blueprint('myBlueprint')

            self.engine.do('destroy')
            self.engine.destroy_all_blueprints()
            self.engine.destroy_blueprint('myBlueprint')

        except socket.gaierror:
            pass
        except InvalidCredsError:
            pass

    def test_lookup(self):

        self.engine = PlumberyEngine()
        self.assertEqual(self.engine.lookup('plumbery.version'), __version__)

        random = self.engine.lookup('random.secret')
        self.assertEqual(len(random), 9)
        self.assertEqual(self.engine.lookup('random.secret'), random)

    def test_parser(self):
        args = parse_args(['fittings.yaml', 'build', 'web'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'build')
        self.assertEqual(args.blueprints, ['web'])
        self.assertEqual(args.facilities, None)
        args = parse_args(['fittings.yaml', 'build', 'web', '-d'])
        self.assertEqual(
            logging.getLogger().getEffectiveLevel(), logging.DEBUG)
        args = parse_args(['fittings.yaml', 'build', 'web', '-q'])
        self.assertEqual(
            logging.getLogger().getEffectiveLevel(), logging.WARNING)
        args = parse_args(['fittings.yaml', 'start', '@NA12'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'start')
        self.assertEqual(args.blueprints, None)
        self.assertEqual(args.facilities, ['NA12'])
        args = parse_args([
            'fittings.yaml', 'rub', 'web', 'sql', '@NA9', '@NA12'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'rub')
        self.assertEqual(args.blueprints, ['web', 'sql'])
        self.assertEqual(args.facilities, ['NA9', 'NA12'])
        args = parse_args([
            'fittings.yaml', 'rub', 'web', '@NA9', 'sql', '@NA12'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'rub')
        self.assertEqual(args.blueprints, ['web', 'sql'])
        self.assertEqual(args.facilities, ['NA9', 'NA12'])
        args = parse_args(['fittings.yaml', 'polish'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'polish')
        self.assertEqual(args.blueprints, None)
        self.assertEqual(args.facilities, None)

    def test_main(self):
        engine = PlumberyEngine()
        engine.from_text(myPlan)
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')
        with self.assertRaises(SystemExit):
            main(['bad args'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml', 'xyz123', 'web'], engine)
        with self.assertRaises(SystemExit):
            main(['-v'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml', 'build', 'web', '-v'], engine)
コード例 #27
0
ファイル: test_engine.py プロジェクト: fxcasadei/plumbery
class TestPlumberyEngine(unittest.TestCase):

    def test_configure(self):

        settings = {
            'safeMode': False,
            'polishers': [
                {'ansible': {}},
                {'spit': {}},
                ]
            }

        self.engine = PlumberyEngine()
        self.engine.set_shared_secret('fake_secret')
        self.assertEqual(self.engine.get_shared_secret(), 'fake_secret')

        self.engine.set_user_name('fake_name')
        self.assertEqual(self.engine.get_user_name(), 'fake_name')

        self.engine.set_user_password('fake_password')
        self.assertEqual(self.engine.get_user_password(), 'fake_password')

        self.engine.configure(settings)
        self.assertEqual(self.engine.safeMode, False)

        try:
            self.engine.setup(io.TextIOWrapper(io.BytesIO(myPlan)))
            self.engine.add_facility(myFacility)
            self.assertEqual(len(self.engine.facilities), 2)

        except socket.gaierror:
            pass
        except InvalidCredsError:
            pass

    def test_lifecycle(self):

        self.engine = PlumberyEngine()
        self.engine.set_shared_secret('fake_secret')
        self.assertEqual(self.engine.get_shared_secret(), 'fake_secret')

        self.engine.set_user_name('fake_name')
        self.assertEqual(self.engine.get_user_name(), 'fake_name')

        self.engine.set_user_password('fake_password')
        self.assertEqual(self.engine.get_user_password(), 'fake_password')

        try:
            self.engine.build_all_blueprints()
            self.engine.build_blueprint('myBlueprint')

            self.engine.start_all_nodes()
            self.engine.start_nodes('myBlueprint')

            self.engine.stop_all_nodes()
            self.engine.stop_nodes('myBlueprint')

            self.engine.destroy_all_nodes()
            self.engine.destroy_nodes('myBlueprint')

        except socket.gaierror:
            pass
        except InvalidCredsError:
            pass
コード例 #28
0
ファイル: test_engine.py プロジェクト: hgolla-repos/plumbery
    def test_set(self):

        engine = PlumberyEngine()
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

        file = os.path.abspath(
            os.path.dirname(__file__)) + '/fixtures/dummy_rsa.pub'

        settings = {
            'keys': ["*hello-there*"],
        }

        with self.assertRaises(ValueError):
            engine.set_settings(settings)

        settings = {
            'keys': [file],
        }

        engine.set_settings(settings)
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertTrue(file in engine.get_shared_key_files())

        settings = {
            'safeMode': False,
            'polishers': [
                {
                    'ansible': {}
                },
                {
                    'configure': {}
                },
            ],
            'keys': [file, file],
        }

        engine.set_settings(settings)
        self.assertEqual(engine.safeMode, False)
        self.assertTrue(isinstance(engine.get_shared_key_files(), list))
        self.assertTrue(file in engine.get_shared_key_files())

        engine.add_facility(myFacility)
        self.assertEqual(len(engine.facilities), 1)

        self.assertEqual(engine.get_shared_user(), 'root')
        engine.set_shared_user('ubuntu')
        self.assertEqual(engine.get_shared_user(), 'ubuntu')

        engine.set_shared_secret('fake_secret')
        self.assertEqual(engine.get_shared_secret(), 'fake_secret')

        random = engine.get_secret('random')
        self.assertEqual(len(random), 9)
        self.assertEqual(engine.get_secret('random'), random)

        engine.set_user_name('fake_name')
        self.assertEqual(engine.get_user_name(), 'fake_name')

        engine.set_user_password('fake_password')
        self.assertEqual(engine.get_user_password(), 'fake_password')
コード例 #29
0
class TestPlumberyFacility(unittest.TestCase):

    def setUp(self):
        self.plumbery = PlumberyEngine()
        self.plumbery.set_user_name('fake_user')
        self.plumbery.set_user_password('fake_password')
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.plumbery.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)
        self.facility = PlumberyFacility(
            plumbery=self.plumbery, fittings=fakeFittings)
        self.facility.power_on()

    def tearDown(self):
        self.facility = None

    def test_get_location_id(self):
        self.assertEqual(self.facility.get_location_id(), 'NA9')

    def test_list_basement(self):
        self.assertEqual(self.facility.list_basement(), ['fake1'])

    def test_list_blueprints(self):
        self.assertEqual(self.facility.list_blueprints(), ['fake1', 'fake2'])

    def test_expand_blueprint(self):
        self.assertEqual(
            self.facility.expand_blueprint('fake1'), ['fake1'])
        self.assertEqual(
            self.facility.expand_blueprint('fake1 unknown fake'), ['fake1'])
        self.assertEqual(
            self.facility.expand_blueprint('macro'), ['fake2'])
        self.assertEqual(
            self.facility.expand_blueprint('basement'), ['fake1'])

    def test_get_blueprint(self):
        self.assertEqual(
            self.facility.get_blueprint('fake2')['target'], 'fake2')
        self.assertIsNone(self.facility.get_blueprint('macro'))
        self.assertIsNone(self.facility.get_blueprint('crazyAndunknown'))

    def test_list_domains(self):
        self.assertEqual(self.facility.list_domains(), ['VDC1'])

    def test_list_ethernets(self):
        self.assertEqual(self.facility.list_ethernets(), ['vlan1'])

    def test_list_nodes(self):
        self.assertEqual(self.facility.list_nodes(),
                         ['stackstorm1', 'stackstorm2'])

    def test_get_image(self):
        self.assertRegexpMatches(
            self.facility.get_image().name, "^RedHat ")
        self.assertIsNone(self.facility.get_image('perfectlyUnknown'))

    def test_focus(self):
        self.facility.focus()

    def test_process_all_blueprints(self):
        action = FakeAction({})
        self.facility.process_all_blueprints(action)
        self.assertEqual(action.count, 14)

    def test_process_blueprint(self):
        action = FakeAction({})
        self.facility.process_blueprint(action, names='fake')
        self.assertEqual(action.count, 4)

    def test_build_all_blueprints(self):
        self.facility.build_all_blueprints()

    def test_build_blueprint(self):
        self.facility.build_blueprint('fake')

    def test_start_all_blueprints(self):
        self.facility.start_all_blueprints()

    def test_start_blueprint(self):
        self.facility.start_blueprint('fake')

    def test_polish_all_blueprints(self):
        self.facility.polish_all_blueprints(polishers='ping')

    def test_polish_blueprint(self):
        self.facility.polish_blueprint(names='fake', polishers='ping')

    def test_stop_all_blueprints(self):
        self.facility.stop_all_blueprints()

    def test_stop_blueprint(self):
        self.facility.stop_blueprint('fake')

    def test_wipe_all_blueprints(self):
        self.facility.wipe_all_blueprints()

    def test_wipe_blueprint(self):
        self.facility.wipe_blueprint('fake')

    def test_destroy_all_blueprints(self):
        self.facility.destroy_all_blueprints()

    def test_destroy_blueprint(self):
        self.facility.destroy_blueprint('fake')

    def test_lookup(self):
        self.assertEqual(self.facility.lookup('location.country'), 'US')
        self.assertEqual(self.facility.lookup('location.id'), 'NA9')
        self.assertEqual(self.facility.lookup('*unknown*'), None)

    def test_settings(self):
        engine = PlumberyEngine(defaultsPlan)
        facility = engine.list_facility('EU6')[0]
        self.assertEqual(facility.get_setting('locationId'), 'EU6')
        self.assertEqual(facility.get_setting('regionId'), 'dd-eu')
        self.assertEqual(facility.get_setting('prepare'), None)
        self.assertEqual(facility.get_setting('basement'), 'myBlueprint')

    def test_settings_private(self):
        settings = {
            'apiHost': 'smee.com',
            'locationId': 'NA5',
            'safeMode': True
        }
        engine = PlumberyEngine(plan=settings)
        engine.set_user_name('smee')
        engine.set_user_password('smee')
        facility = engine.list_facility()[0]
#        facility.power_on()
        self.assertEqual(facility.get_setting('locationId'), 'NA5')
        self.assertIsNone(facility.get_setting('regionId'))

    def test_blueprints(self):
        engine = PlumberyEngine(defaultsPlan)
        facility = engine.list_facility('EU6')[0]
        blueprint = facility.get_blueprint('myBlueprint')
        self.assertEqual(isinstance(blueprint, dict), True)
        self.assertEqual(blueprint['domain']['name'], 'myDC')
        self.assertEqual(blueprint['domain']['ipv4'], 'auto')
        self.assertEqual(blueprint['ethernet']['name'], 'myVLAN')
        self.assertEqual(blueprint['ethernet']['subnet'], '10.1.10.0')
        self.assertEqual(len(blueprint['ethernet']['accept']), 1)
        label = list(blueprint['nodes'][0])[0]
        node = blueprint['nodes'][0][label]
        self.assertEqual('default' not in node, True)
        self.assertEqual(node['cpu'], 3)
        self.assertEqual(node['memory'], 5)
        self.assertEqual(len(node['information']), 2)
        config = node['cloud-config']
        self.assertEqual(isinstance(config, dict), True)
        self.assertEqual(config['disable_root'], True)
        self.assertEqual(config['ssh_pwauth'], True)
        self.assertEqual(len(config['packages']), 4)
        self.assertEqual(len(config['runcmd']), 4)
コード例 #30
0
class MonitoringConfigurationTests(unittest.TestCase):
    def setUp(self):
        self.plumbery = PlumberyEngine()
        self.plumbery.set_user_name('fake_user')
        self.plumbery.set_user_password('fake_password')
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.plumbery.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)
        self.facility = PlumberyFacility(
            plumbery=self.plumbery, fittings=myFacility)
        self.facility.power_on()

    def test_monitoring_validation_valid(self):
        settings = {
            'monitoring': 'essentials'
        }
        config = monitoring.MonitoringConfiguration(engine=None, facility=None)
        self.assertTrue(config.validate(settings))

    def test_monitoring_validation_invalid(self):
        settings = {
            'monitoring': 'potato'
        }
        config = monitoring.MonitoringConfiguration(engine=None, facility=None)
        with self.assertRaises(ConfigurationError):
            config.validate(settings)

    def test_monitoring_configuration(self):
        settings = {
            'monitoring': 'essentials',
        }
        config = monitoring.MonitoringConfiguration(engine=None, facility=None)
        node = TestNode()
        config._start_monitoring = MagicMock(return_value=True)
        config.configure(node, settings)
        self.assertTrue(config)
        config._start_monitoring.assert_called_with(node, 'ESSENTIALS')

    def test_monitoring_configuration_deep(self):
        settings = {
            'monitoring': 'essentials',
        }
        config = monitoring.MonitoringConfiguration(engine=self.plumbery,
                                                    facility=self.facility)
        node = TestNode()
        config.configure(node, settings)
        self.assertTrue(config)

    def test_monitoring_deconfiguration(self):
        settings = {
            'monitoring': 'essentials',
        }
        config = monitoring.MonitoringConfiguration(engine=None, facility=None)
        node = TestNode()
        config._stop_monitoring = MagicMock(return_value=True)
        config.deconfigure(node, settings)
        self.assertTrue(config)
        config._stop_monitoring.assert_called_with(node, settings)

    def test_monitoring_deconfiguration_deep(self):
        settings = {
            'monitoring': 'essentials',
        }
        config = monitoring.MonitoringConfiguration(engine=self.plumbery,
                                                    facility=self.facility)
        node = TestNode()
        config.deconfigure(node, settings)
        self.assertTrue(config)
コード例 #31
0
 def test_main(self):
     engine = PlumberyEngine()
     engine.from_text(myPlan)
     engine.set_user_name('fake_name')
     engine.set_user_password('fake_password')
コード例 #32
0
class TestPlumberyEngine(unittest.TestCase):
    def test_set(self):

        settings = {
            'safeMode': False,
            'polishers': [
                {
                    'ansible': {}
                },
                {
                    'spit': {}
                },
            ]
        }

        self.engine = PlumberyEngine()
        self.engine.set_shared_secret('fake_secret')
        self.assertEqual(self.engine.get_shared_secret(), 'fake_secret')

        self.engine.set_user_name('fake_name')
        self.assertEqual(self.engine.get_user_name(), 'fake_name')

        self.engine.set_user_password('fake_password')
        self.assertEqual(self.engine.get_user_password(), 'fake_password')

        self.engine.set(settings)
        self.assertEqual(self.engine.safeMode, False)

        try:
            self.engine.from_text(myPlan)
            self.engine.add_facility(myFacility)
            self.assertEqual(len(self.engine.facilities), 2)

        except socket.gaierror:
            pass
        except InvalidCredsError:
            pass

    def test_lifecycle(self):

        self.engine = PlumberyEngine()
        self.engine.set_shared_secret('fake_secret')
        self.assertEqual(self.engine.get_shared_secret(), 'fake_secret')

        self.engine.set_user_name('fake_name')
        self.assertEqual(self.engine.get_user_name(), 'fake_name')

        self.engine.set_user_password('fake_password')
        self.assertEqual(self.engine.get_user_password(), 'fake_password')

        try:
            self.engine.build_all_blueprints()
            self.engine.build_blueprint('myBlueprint')

            self.engine.start_all_nodes()
            self.engine.start_nodes('myBlueprint')

            self.engine.polish_all_blueprints()
            self.engine.polish_blueprint('myBlueprint')

            self.engine.stop_all_nodes()
            self.engine.stop_nodes('myBlueprint')

            self.engine.destroy_all_nodes()
            self.engine.destroy_nodes('myBlueprint')

            self.engine.destroy_all_blueprints()
            self.engine.destroy_blueprint('myBlueprint')

        except socket.gaierror:
            pass
        except InvalidCredsError:
            pass

    def test_parser(self):
        with self.assertRaises(SystemExit):
            args = parse_args(['bad args'])
        with self.assertRaises(SystemExit):
            args = parse_args(['fittings.yaml'])
        args = parse_args(['fittings.yaml', 'build', 'web'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'build')
        self.assertEqual(args.blueprints, ['web'])
        self.assertEqual(args.facilities, None)
        args = parse_args(['fittings.yaml', 'start', '@NA12'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'start')
        self.assertEqual(args.blueprints, None)
        self.assertEqual(args.facilities, ['NA12'])
        args = parse_args(
            ['fittings.yaml', 'rub', 'web', 'sql', '@NA9', '@NA12'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'rub')
        self.assertEqual(args.blueprints, ['web', 'sql'])
        self.assertEqual(args.facilities, ['NA9', 'NA12'])
        args = parse_args(['fittings.yaml', 'polish'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'polish')
        self.assertEqual(args.blueprints, None)
        self.assertEqual(args.facilities, None)

    def test_main(self):
        engine = PlumberyEngine()
        engine.from_text(myPlan)
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')
コード例 #33
0
class TestPlumberyFacility(unittest.TestCase):

    def setUp(self):
        self.plumbery = PlumberyEngine()
        self.plumbery.set_user_name('fake_user')
        self.plumbery.set_user_password('fake_password')
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.facility = PlumberyFacility(
            plumbery=self.plumbery, fittings=fakeFittings)
        self.facility.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)

    def tearDown(self):
        self.facility = None

    def test_get_location_id(self):
        self.assertEqual(self.facility.get_location_id(), 'NA9')

    def test_list_basement(self):
        self.assertEqual(self.facility.list_basement(), ['fake'])

    def test_list_blueprints(self):
        self.assertEqual(self.facility.list_blueprints(), ['fake'])

    def test_expand_blueprint(self):
        self.assertEqual(
            self.facility.expand_blueprint('fake'), ['fake'])
        self.assertEqual(
            self.facility.expand_blueprint('fake unknown fake'), ['fake'])
        self.assertEqual(
            self.facility.expand_blueprint('macro'), ['fake'])
        self.assertEqual(
            self.facility.expand_blueprint('basement'), ['fake'])

    def test_get_blueprint(self):
        self.assertEqual(
            self.facility.get_blueprint('fake')['target'], 'fake')
        self.assertIsNone(self.facility.get_blueprint('macro'))
        self.assertIsNone(self.facility.get_blueprint('crazyAndunknown'))

    def test_list_domains(self):
        self.assertEqual(self.facility.list_domains(), ['VDC1'])

    def test_list_ethernets(self):
        self.assertEqual(self.facility.list_ethernets(), ['vlan1'])

    def test_list_nodes(self):
        self.assertEqual(self.facility.list_nodes(), ['stackstorm'])

    def test_get_image(self):
        self.assertRegexpMatches(
            self.facility.get_image().name, "^RedHat ")
        self.assertIsNone(self.facility.get_image('perfectlyUnknown'))

    def test_focus(self):
        self.facility.focus()

    def test_build_all_blueprints(self):
        self.facility.build_all_blueprints()

    def test_build_blueprint(self):
        self.facility.build_blueprint('fake')

    def test_start_all_blueprints(self):
        self.facility.start_all_blueprints()

    def test_start_blueprint(self):
        self.facility.start_blueprint('fake')

    def test_polish_all_blueprints(self):
        self.facility.polish_all_blueprints(polishers='ping')

    def test_polish_blueprint(self):
        self.facility.polish_blueprint(names='fake', polishers='ping')

    def test_stop_all_blueprints(self):
        self.facility.stop_all_blueprints()

    def test_stop_blueprint(self):
        self.facility.stop_blueprint('fake')

    def test_wipe_all_blueprints(self):
        self.facility.wipe_all_blueprints()

    def test_wipe_blueprint(self):
        self.facility.wipe_blueprint('fake')

    def test_destroy_all_blueprints(self):
        self.facility.destroy_all_blueprints()

    def test_destroy_blueprint(self):
        self.facility.destroy_blueprint('fake')

    def test_lookup(self):
        self.assertEqual(self.facility.lookup('*unknown*'), None)

    def test_get_parameter(self):

        engine = PlumberyEngine()
        engine.from_text(defaultsPlan)
        facility = engine.list_facility('EU6')[0]
        self.assertEqual(facility.get_parameter('locationId'), 'EU6')
        self.assertEqual(facility.get_parameter('regionId'), 'dd-eu')
        self.assertEqual(facility.get_parameter('rub'), None)
        self.assertEqual(facility.get_parameter('ipv4'), 'auto')
        self.assertEqual(facility.get_parameter('basement'), 'myBlueprint')
コード例 #34
0
class TestPlumberyEngine(unittest.TestCase):

    def test_set(self):

        settings = {
            'safeMode': False,
            'polishers': [
                {'ansible': {}},
                {'spit': {}},
                ]
            }

        self.engine = PlumberyEngine()
        self.engine.set_shared_secret('fake_secret')
        self.assertEqual(self.engine.get_shared_secret(), 'fake_secret')

        random = self.engine.get_secret('random')
        self.assertEqual(len(random), 9)
        self.assertEqual(self.engine.get_secret('random'), random)

        self.engine.set_user_name('fake_name')
        self.assertEqual(self.engine.get_user_name(), 'fake_name')

        self.engine.set_user_password('fake_password')
        self.assertEqual(self.engine.get_user_password(), 'fake_password')

        self.engine.set(settings)
        self.assertEqual(self.engine.safeMode, False)

        try:
            self.engine.from_text(myPlan)
            cloudConfig = self.engine.get_cloud_config()
            self.assertEqual(len(cloudConfig.keys()), 3)
            self.engine.add_facility(myFacility)
            self.assertEqual(len(self.engine.facilities), 2)

        except socket.gaierror:
            pass
        except InvalidCredsError:
            pass

    def test_lifecycle(self):

        self.engine = PlumberyEngine()
        self.engine.set_shared_secret('fake_secret')
        self.assertEqual(self.engine.get_shared_secret(), 'fake_secret')

        self.engine.set_user_name('fake_name')
        self.assertEqual(self.engine.get_user_name(), 'fake_name')

        self.engine.set_user_password('fake_password')
        self.assertEqual(self.engine.get_user_password(), 'fake_password')

        try:
            self.engine.do('build')
            self.engine.build_all_blueprints()
            self.engine.build_blueprint('myBlueprint')

            self.engine.do('start')
            self.engine.start_all_blueprints()
            self.engine.start_blueprint('myBlueprint')

            self.engine.do('polish')
            self.engine.polish_all_blueprints()
            self.engine.polish_blueprint('myBlueprint')

            self.engine.do('stop')
            self.engine.stop_all_blueprints()
            self.engine.stop_blueprint('myBlueprint')

            self.engine.wipe_all_blueprints()
            self.engine.wipe_blueprint('myBlueprint')

            self.engine.do('destroy')
            self.engine.destroy_all_blueprints()
            self.engine.destroy_blueprint('myBlueprint')

        except socket.gaierror:
            pass
        except InvalidCredsError:
            pass

    def test_lookup(self):

        self.engine = PlumberyEngine()
        self.assertEqual(self.engine.lookup('plumbery.version'), __version__)

        self.engine.secrets = {}
        random = self.engine.lookup('random.secret')
        self.assertEqual(len(random), 9)
        self.assertEqual(self.engine.lookup('random.secret'), random)

        md5 = self.engine.lookup('random.md5.secret')
        self.assertEqual(len(md5), 32)
        self.assertNotEqual(md5, random)

        sha = self.engine.lookup('random.sha1.secret')
        self.assertEqual(len(sha), 40)
        self.assertNotEqual(sha, random)

        sha = self.engine.lookup('random.sha256.secret')
        self.assertEqual(len(sha), 64)
        self.assertNotEqual(sha, random)

        id1 = self.engine.lookup('id1.uuid')
        self.assertEqual(len(id1), 36)
        self.assertEqual(self.engine.lookup('id1.uuid'), id1)
        id2 = self.engine.lookup('id2.uuid')
        self.assertEqual(len(id2), 36)
        self.assertNotEqual(id1, id2)

        self.engine.lookup('application.secret')
        self.engine.lookup('database.secret')
        self.engine.lookup('master.secret')
        self.engine.lookup('slave.secret')

        original = 'hello world'
        text = self.engine.lookup('pair1.rsa_public')
        self.assertEqual(text.startswith('ssh-rsa '), True)
        key = RSA.importKey(text)
        encrypted = key.publickey().encrypt(original, 32)

        privateKey = self.engine.lookup('pair1.rsa_private')
        self.assertEqual(privateKey.startswith(
            '-----BEGIN RSA PRIVATE KEY-----'), True)
        key = RSA.importKey(self.engine.lookup('pair1.rsa_private'))
        decrypted = key.decrypt(ast.literal_eval(str(encrypted)))
        self.assertEqual(decrypted, original)

        self.assertEqual(len(self.engine.secrets), 12)

        with self.assertRaises(LookupError):
            localKey = self.engine.lookup('local.rsa_private')

        localKey = self.engine.lookup('local.rsa_public')
        try:
            path = '~/.ssh/id_rsa.pub'
            with open(os.path.expanduser(path)) as stream:
                text = stream.read()
                stream.close()
                self.assertEqual(localKey.strip(), text.strip())
                logging.info("Successful lookup of local public key")

        except IOError:
            pass

    def test_secrets(self):

        engine = PlumberyEngine()
        engine.secrets = {'hello': 'world'}
        engine.save_secrets(plan='test_engine.yaml')
        self.assertEqual(os.path.isfile('.test_engine.secrets'), True)
        engine.secrets = {}
        engine.load_secrets(plan='test_engine.yaml')
        self.assertEqual(engine.secrets['hello'], 'world')
        engine.forget_secrets(plan='test_engine.yaml')
        self.assertEqual(os.path.isfile('.test_engine.secrets'), False)

    def test_defaults(self):

        engine = PlumberyEngine()
        engine.from_text(defaultsPlan)
        self.assertEqual(engine.get_default('locationId'), 'EU6')
        self.assertEqual(engine.get_default('regionId'), 'dd-eu')
        self.assertEqual(engine.get_default('ipv4'), 'auto')

    def test_parser(self):
        args = parse_args(['fittings.yaml', 'build', 'web'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'build')
        self.assertEqual(args.blueprints, ['web'])
        self.assertEqual(args.facilities, None)
        args = parse_args(['fittings.yaml', 'build', 'web', '-d'])
        self.assertEqual(
            logging.getLogger().getEffectiveLevel(), logging.DEBUG)
        args = parse_args(['fittings.yaml', 'build', 'web', '-q'])
        self.assertEqual(
            logging.getLogger().getEffectiveLevel(), logging.WARNING)
        args = parse_args(['fittings.yaml', 'start', '@NA12'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'start')
        self.assertEqual(args.blueprints, None)
        self.assertEqual(args.facilities, ['NA12'])
        args = parse_args([
            'fittings.yaml', 'rub', 'web', 'sql', '@NA9', '@NA12'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'rub')
        self.assertEqual(args.blueprints, ['web', 'sql'])
        self.assertEqual(args.facilities, ['NA9', 'NA12'])
        args = parse_args([
            'fittings.yaml', 'rub', 'web', '@NA9', 'sql', '@NA12'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'rub')
        self.assertEqual(args.blueprints, ['web', 'sql'])
        self.assertEqual(args.facilities, ['NA9', 'NA12'])
        args = parse_args(['fittings.yaml', 'polish'])
        self.assertEqual(args.fittings, 'fittings.yaml')
        self.assertEqual(args.action, 'polish')
        self.assertEqual(args.blueprints, None)
        self.assertEqual(args.facilities, None)

    def test_main(self):
        engine = PlumberyEngine()
        engine.from_text(myPlan)
        engine.set_user_name('fake_name')
        engine.set_user_password('fake_password')
        with self.assertRaises(SystemExit):
            main(['bad args'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml', 'xyz123', 'web'], engine)
        with self.assertRaises(SystemExit):
            main(['-v'], engine)
        with self.assertRaises(SystemExit):
            main(['fittings.yaml', 'build', 'web', '-v'], engine)
コード例 #35
0
class MonitoringConfigurationTests(unittest.TestCase):
    def setUp(self):
        self.plumbery = PlumberyEngine()
        self.plumbery.set_user_name('fake_user')
        self.plumbery.set_user_password('fake_password')
        DimensionDataNodeDriver.connectionCls.conn_classes = (
            None, DimensionDataMockHttp)
        DimensionDataMockHttp.type = None
        self.plumbery.region = DimensionDataNodeDriver(*DIMENSIONDATA_PARAMS)
        self.facility = PlumberyFacility(plumbery=self.plumbery,
                                         fittings=myFacility)
        self.facility.power_on()

    def test_monitoring_validation_valid(self):
        settings = {'monitoring': 'essentials'}
        config = monitoring.MonitoringConfiguration(engine=None, facility=None)
        self.assertTrue(config.validate(settings))

    def test_monitoring_validation_invalid(self):
        settings = {'monitoring': 'potato'}
        config = monitoring.MonitoringConfiguration(engine=None, facility=None)
        with self.assertRaises(ConfigurationError):
            config.validate(settings)

    def test_monitoring_configuration(self):
        settings = {
            'monitoring': 'essentials',
        }
        config = monitoring.MonitoringConfiguration(engine=None, facility=None)
        node = TestNode()
        config._start_monitoring = MagicMock(return_value=True)
        config.configure(node, settings)
        self.assertTrue(config)
        config._start_monitoring.assert_called_with(node, 'ESSENTIALS')

    def test_monitoring_configuration_deep(self):
        settings = {
            'monitoring': 'essentials',
        }
        config = monitoring.MonitoringConfiguration(engine=self.plumbery,
                                                    facility=self.facility)
        node = TestNode()
        config.configure(node, settings)
        self.assertTrue(config)

    def test_monitoring_deconfiguration(self):
        settings = {
            'monitoring': 'essentials',
        }
        config = monitoring.MonitoringConfiguration(engine=None, facility=None)
        node = TestNode()
        config._stop_monitoring = MagicMock(return_value=True)
        config.deconfigure(node, settings)
        self.assertTrue(config)
        config._stop_monitoring.assert_called_with(node, settings)

    def test_monitoring_deconfiguration_deep(self):
        settings = {
            'monitoring': 'essentials',
        }
        config = monitoring.MonitoringConfiguration(engine=self.plumbery,
                                                    facility=self.facility)
        node = TestNode()
        config.deconfigure(node, settings)
        self.assertTrue(config)