Exemple #1
0
    def setUp(self):
        super(PeriodicTestCase, self).setUp()

        ctx = context.make_admin_context()

        bay1 = utils.get_test_bay(id=1,
                                  stack_id='11',
                                  status=bay_status.CREATE_IN_PROGRESS)
        bay2 = utils.get_test_bay(id=2,
                                  stack_id='22',
                                  status=bay_status.DELETE_IN_PROGRESS)
        bay3 = utils.get_test_bay(id=3,
                                  stack_id='33',
                                  status=bay_status.UPDATE_IN_PROGRESS)
        bay4 = utils.get_test_bay(id=4,
                                  stack_id='44',
                                  status=bay_status.CREATE_COMPLETE)

        self.bay1 = objects.Bay(ctx, **bay1)
        self.bay2 = objects.Bay(ctx, **bay2)
        self.bay3 = objects.Bay(ctx, **bay3)
        self.bay4 = objects.Bay(ctx, **bay4)

        mock_magnum_service_refresh = mock.Mock()

        class FakeMS(object):
            report_state_up = mock_magnum_service_refresh

        self.fake_ms = FakeMS()
        self.fake_ms_refresh = mock_magnum_service_refresh
Exemple #2
0
    def setUp(self):
        super(PeriodicTestCase, self).setUp()

        ctx = context.make_admin_context()

        # Can be identical for all bays.
        trust_attrs = {
            'trustee_username': '******',
            'trustee_password': '******',
            'trust_id': '39d920ca-67c6-4047-b57a-01e9e16bb96f',
            }

        trust_attrs.update({'id': 1, 'stack_id': '11',
                           'status': bay_status.CREATE_IN_PROGRESS})
        bay1 = utils.get_test_bay(**trust_attrs)
        trust_attrs.update({'id': 2, 'stack_id': '22',
                           'status': bay_status.DELETE_IN_PROGRESS})
        bay2 = utils.get_test_bay(**trust_attrs)
        trust_attrs.update({'id': 3, 'stack_id': '33',
                           'status': bay_status.UPDATE_IN_PROGRESS})
        bay3 = utils.get_test_bay(**trust_attrs)
        trust_attrs.update({'id': 4, 'stack_id': '44',
                           'status': bay_status.CREATE_COMPLETE})
        bay4 = utils.get_test_bay(**trust_attrs)

        self.bay1 = objects.Bay(ctx, **bay1)
        self.bay2 = objects.Bay(ctx, **bay2)
        self.bay3 = objects.Bay(ctx, **bay3)
        self.bay4 = objects.Bay(ctx, **bay4)
Exemple #3
0
    def test_get_pod_list_with_filters(self):
        bay1 = utils.get_test_bay(id=11, uuid=magnum_utils.generate_uuid())
        bay2 = utils.get_test_bay(id=12, uuid=magnum_utils.generate_uuid())
        self.dbapi.create_bay(bay1)
        self.dbapi.create_bay(bay2)

        pod1 = utils.create_test_pod(
            name="pod-one", uuid=magnum_utils.generate_uuid(), bay_uuid=bay1["uuid"], status="status1"
        )
        pod2 = utils.create_test_pod(
            name="pod-two", uuid=magnum_utils.generate_uuid(), bay_uuid=bay2["uuid"], status="status2"
        )

        res = self.dbapi.get_pod_list(self.context, filters={"bay_uuid": bay1["uuid"]})
        self.assertEqual([pod1.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context, filters={"bay_uuid": bay2["uuid"]})
        self.assertEqual([pod2.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context, filters={"name": "pod-one"})
        self.assertEqual([pod1.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context, filters={"name": "bad-pod"})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context, filters={"status": "status1"})
        self.assertEqual([pod1.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context, filters={"status": "status2"})
        self.assertEqual([pod2.id], [r.id for r in res])
Exemple #4
0
    def test_get_x509keypair_list_with_filters(self):
        bay1 = utils.get_test_bay(id=1, uuid=magnum_utils.generate_uuid())
        bay2 = utils.get_test_bay(id=2, uuid=magnum_utils.generate_uuid())
        self.dbapi.create_bay(bay1)
        self.dbapi.create_bay(bay2)

        x509keypair1 = utils.create_test_x509keypair(
            name='x509keypair-one',
            uuid=magnum_utils.generate_uuid(),
            bay_uuid=bay1['uuid'])
        x509keypair2 = utils.create_test_x509keypair(
            name='x509keypair-two',
            uuid=magnum_utils.generate_uuid(),
            bay_uuid=bay2['uuid'])
        x509keypair3 = utils.create_test_x509keypair(
            name='x509keypair-three',
            bay_uuid=bay2['uuid'])

        res = self.dbapi.get_x509keypair_list(
            self.context, filters={'bay_uuid': bay1['uuid']})
        self.assertEqual([x509keypair1.id], [r.id for r in res])

        res = self.dbapi.get_x509keypair_list(
            self.context, filters={'bay_uuid': bay2['uuid']})
        self.assertEqual([x509keypair2.id, x509keypair3.id],
                         [r.id for r in res])

        res = self.dbapi.get_x509keypair_list(
            self.context, filters={'name': 'x509keypair-one'})
        self.assertEqual([x509keypair1.id], [r.id for r in res])

        res = self.dbapi.get_x509keypair_list(
            self.context, filters={'name': 'bad-x509keypair'})
        self.assertEqual([], [r.id for r in res])
Exemple #5
0
    def setUp(self):
        super(PeriodicTestCase, self).setUp()

        ctx = context.make_admin_context()

        bay1 = utils.get_test_bay(id=1, stack_id='11',
                                  status=bay_status.CREATE_IN_PROGRESS)
        bay2 = utils.get_test_bay(id=2, stack_id='22',
                                  status=bay_status.DELETE_IN_PROGRESS)
        bay3 = utils.get_test_bay(id=3, stack_id='33',
                                  status=bay_status.UPDATE_IN_PROGRESS)
        bay4 = utils.get_test_bay(id=4, stack_id='44',
                                  status=bay_status.CREATE_COMPLETE)

        self.bay1 = objects.Bay(ctx, **bay1)
        self.bay2 = objects.Bay(ctx, **bay2)
        self.bay3 = objects.Bay(ctx, **bay3)
        self.bay4 = objects.Bay(ctx, **bay4)

        mock_magnum_service_refresh = mock.Mock()

        class FakeMS(object):
            report_state_up = mock_magnum_service_refresh

        self.fake_ms = FakeMS()
        self.fake_ms_refresh = mock_magnum_service_refresh
Exemple #6
0
    def setUp(self):
        super(PeriodicTestCase, self).setUp()

        ctx = context.make_admin_context()

        bay1 = utils.get_test_bay(id=1, stack_id='11',
                                  status=bay_status.CREATE_IN_PROGRESS)
        bay2 = utils.get_test_bay(id=2, stack_id='22',
                                  status=bay_status.DELETE_IN_PROGRESS)
        bay3 = utils.get_test_bay(id=3, stack_id='33',
                                  status=bay_status.UPDATE_IN_PROGRESS)

        self.bay1 = objects.Bay(ctx, **bay1)
        self.bay2 = objects.Bay(ctx, **bay2)
        self.bay3 = objects.Bay(ctx, **bay3)
Exemple #7
0
    def setUp(self):
        super(PeriodicTestCase, self).setUp()

        ctx = context.make_admin_context()

        # Can be identical for all bays.
        trust_attrs = {
            'trustee_username': '******',
            'trustee_password': '******',
            'trust_id': '39d920ca-67c6-4047-b57a-01e9e16bb96f',
        }

        trust_attrs.update({
            'id': 1,
            'stack_id': '11',
            'status': bay_status.CREATE_IN_PROGRESS
        })
        bay1 = utils.get_test_bay(**trust_attrs)
        trust_attrs.update({
            'id': 2,
            'stack_id': '22',
            'status': bay_status.DELETE_IN_PROGRESS
        })
        bay2 = utils.get_test_bay(**trust_attrs)
        trust_attrs.update({
            'id': 3,
            'stack_id': '33',
            'status': bay_status.UPDATE_IN_PROGRESS
        })
        bay3 = utils.get_test_bay(**trust_attrs)
        trust_attrs.update({
            'id': 4,
            'stack_id': '44',
            'status': bay_status.CREATE_COMPLETE
        })
        bay4 = utils.get_test_bay(**trust_attrs)
        trust_attrs.update({
            'id': 5,
            'stack_id': '55',
            'status': bay_status.ROLLBACK_IN_PROGRESS
        })
        bay5 = utils.get_test_bay(**trust_attrs)

        self.bay1 = objects.Bay(ctx, **bay1)
        self.bay2 = objects.Bay(ctx, **bay2)
        self.bay3 = objects.Bay(ctx, **bay3)
        self.bay4 = objects.Bay(ctx, **bay4)
        self.bay5 = objects.Bay(ctx, **bay5)
Exemple #8
0
def bay_post_data(**kw):
    bay = utils.get_test_bay(**kw)
    # the timeout property is a part of the request and doesn't persist
    # in the bay db
    bay['bay_create_timeout'] = kw.get('bay_create_timeout', 15)
    internal = bay_controller.BayPatchType.internal_attrs()
    return remove_internal(bay, internal)
Exemple #9
0
 def setUp(self):
     super(RPCAPITestCase, self).setUp()
     self.fake_bay = dbutils.get_test_bay(driver='fake-driver')
     self.fake_container = dbutils.get_test_container(driver='fake-driver')
     self.fake_rc = dbutils.get_test_rc(driver='fake-driver')
     self.fake_certificate = objects.Certificate.from_db_bay(self.fake_bay)
     self.fake_certificate.csr = 'fake-csr'
    def test_create_container_with_bay_uuid(self,
                                           mock_container_delete,
                                           mock_container_create,
                                           mock_get_by_uuid):
        mock_container_create.side_effect = lambda x, y, z: z
        # Create a container with a command
        params = ('{"name": "My Docker", "image_id": "ubuntu",'
                  '"command": "env",'
                  '"bay_uuid": "fff114da-3bfa-4a0f-a123-c0dffad9718e"}')
        self.fake_bay = utils.get_test_bay()
        value = self.fake_bay['uuid']
        mock_get_by_uuid.return_value = self.fake_bay
        bay = objects.Bay.get_by_uuid(self.context, value)
        self.assertEqual(value, bay['uuid'])
        response = self.app.post('/v1/containers',
                                 params=params,
                                 content_type='application/json')
        self.assertEqual(response.status_int, 201)
        # get all containers
        response = self.app.get('/v1/containers')
        self.assertEqual(response.status_int, 200)
        self.assertEqual(1, len(response.json))
        c = response.json['containers'][0]
        self.assertIsNotNone(c.get('uuid'))
        self.assertEqual('My Docker', c.get('name'))
        self.assertEqual('env', c.get('command'))
        # Delete the container we created
        response = self.app.delete('/v1/containers/%s' % c.get('uuid'))
        self.assertEqual(response.status_int, 204)

        response = self.app.get('/v1/containers')
        self.assertEqual(response.status_int, 200)
        c = response.json['containers']
        self.assertEqual(0, len(c))
        self.assertTrue(mock_container_create.called)
Exemple #11
0
 def fake_get_by_uuid(context, uuid):
     bay_dict = utils.get_test_bay(uuid=uuid)
     baymodel = obj_utils.get_test_baymodel(
         context, coe='swarm', uuid=bay_dict['baymodel_id'])
     bay = objects.Bay(self.context, **bay_dict)
     bay.baymodel = baymodel
     return bay
Exemple #12
0
 def fake_get_by_uuid(context, uuid):
     bay_dict = utils.get_test_bay(uuid=uuid)
     baymodel = obj_utils.get_test_baymodel(
         context, coe='swarm', uuid=bay_dict['baymodel_id'])
     bay = objects.Bay(self.context, **bay_dict)
     bay.baymodel = baymodel
     return bay
Exemple #13
0
 def setUp(self):
     super(RPCAPITestCase, self).setUp()
     self.fake_bay = dbutils.get_test_bay(driver='fake-driver')
     self.fake_container = dbutils.get_test_container(driver='fake-driver')
     self.fake_pod = dbutils.get_test_pod(driver='fake-driver')
     self.fake_rc = dbutils.get_test_rc(driver='fake-driver')
     self.fake_service = dbutils.get_test_service(driver='fake-driver')
Exemple #14
0
    def test_get_service_list_with_filters(self):
        bay1 = utils.get_test_bay(id=11, uuid=uuidutils.generate_uuid())
        bay2 = utils.get_test_bay(id=12, uuid=uuidutils.generate_uuid())
        self.dbapi.create_bay(bay1)
        self.dbapi.create_bay(bay2)

        service1 = utils.create_test_service(name='service-one',
                                             uuid=uuidutils.generate_uuid(),
                                             bay_uuid=bay1['uuid'],
                                             ports=[{
                                                 'port': 8000
                                             }])
        service2 = utils.create_test_service(name='service-two',
                                             uuid=uuidutils.generate_uuid(),
                                             bay_uuid=bay2['uuid'],
                                             ports=[{
                                                 'port': 8001
                                             }])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'bay_uuid': bay1['uuid']})
        self.assertEqual([service1.id], [r.id for r in res])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'bay_uuid': bay2['uuid']})
        self.assertEqual([service2.id], [r.id for r in res])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'name': 'service-one'})
        self.assertEqual([service1.id], [r.id for r in res])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'name': 'bad-service'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'ports': [{
                                              'port': 8000
                                          }]})
        self.assertEqual([service1.id], [r.id for r in res])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'ports': [{
                                              'port': 8001
                                          }]})
        self.assertEqual([service2.id], [r.id for r in res])
Exemple #15
0
 def setUp(self):
     super(TestHandler, self).setUp()
     self.handler = bay_conductor.Handler()
     baymodel_dict = utils.get_test_baymodel()
     self.baymodel = objects.BayModel(self.context, **baymodel_dict)
     self.baymodel.create()
     bay_dict = utils.get_test_bay(node_count=1)
     self.bay = objects.Bay(self.context, **bay_dict)
     self.bay.create()
Exemple #16
0
 def setUp(self):
     super(TestBayObject, self).setUp()
     self.fake_bay = utils.get_test_bay()
     self.fake_bay['trust_id'] = 'trust_id'
     self.fake_bay['trustee_username'] = '******'
     self.fake_bay['trustee_user_id'] = 'trustee_user_id'
     self.fake_bay['trustee_password'] = '******'
     baymodel_id = self.fake_bay['baymodel_id']
     self.fake_baymodel = objects.BayModel(uuid=baymodel_id)
Exemple #17
0
def cluster_post_data(**kw):
    cluster = utils.get_test_bay(**kw)
    cluster['create_timeout'] = kw.get('create_timeout', 15)
    cluster['cluster_template_id'] = kw.get('cluster_template_id',
                                            cluster['baymodel_id'])
    del cluster['bay_create_timeout']
    del cluster['baymodel_id']
    internal = cluster_controller.ClusterPatchType.internal_attrs()
    return remove_internal(cluster, internal)
Exemple #18
0
 def setUp(self):
     super(TestBayObject, self).setUp()
     self.fake_bay = utils.get_test_bay()
     self.fake_bay['trust_id'] = 'trust_id'
     self.fake_bay['trustee_username'] = '******'
     self.fake_bay['trustee_user_id'] = 'trustee_user_id'
     self.fake_bay['trustee_password'] = '******'
     baymodel_id = self.fake_bay['baymodel_id']
     self.fake_baymodel = objects.BayModel(uuid=baymodel_id)
Exemple #19
0
 def setUp(self):
     super(TestHandler, self).setUp()
     self.handler = bay_conductor.Handler()
     baymodel_dict = utils.get_test_baymodel()
     self.baymodel = objects.BayModel(self.context, **baymodel_dict)
     self.baymodel.create()
     bay_dict = utils.get_test_bay(node_count=1)
     self.bay = objects.Bay(self.context, **bay_dict)
     self.bay.create()
Exemple #20
0
    def setUp(self):
        super(PeriodicTestCase, self).setUp()

        ctx = context.make_admin_context()

        bay1 = utils.get_test_bay(id=1,
                                  stack_id='11',
                                  status=bay_status.CREATE_IN_PROGRESS)
        bay2 = utils.get_test_bay(id=2,
                                  stack_id='22',
                                  status=bay_status.DELETE_IN_PROGRESS)
        bay3 = utils.get_test_bay(id=3,
                                  stack_id='33',
                                  status=bay_status.UPDATE_IN_PROGRESS)

        self.bay1 = objects.Bay(ctx, **bay1)
        self.bay2 = objects.Bay(ctx, **bay2)
        self.bay3 = objects.Bay(ctx, **bay3)
Exemple #21
0
def cluster_post_data(**kw):
    cluster = utils.get_test_bay(**kw)
    cluster['create_timeout'] = kw.get('create_timeout', 15)
    cluster['cluster_template_id'] = kw.get('cluster_template_id',
                                            cluster['baymodel_id'])
    del cluster['bay_create_timeout']
    del cluster['baymodel_id']
    internal = cluster_controller.ClusterPatchType.internal_attrs()
    return remove_internal(cluster, internal)
Exemple #22
0
 def setUp(self):
     super(RPCAPITestCase, self).setUp()
     self.fake_bay = dbutils.get_test_bay(driver='fake-driver')
     self.fake_container = dbutils.get_test_container(driver='fake-driver')
     self.fake_rc = dbutils.get_test_rc(driver='fake-driver')
     self.fake_service = dbutils.get_test_service(driver='fake-driver')
     self.fake_x509keypair = dbutils.get_test_x509keypair(
         driver='fake-driver')
     self.fake_certificate = objects.Certificate.from_db_bay(self.fake_bay)
     self.fake_certificate.csr = 'fake-csr'
 def setUp(self):
     super(TestHandler, self).setUp()
     self.handler = bay_conductor.Handler()
     cluster_template_dict = utils.get_test_cluster_template()
     self.cluster_template = objects.ClusterTemplate(
         self.context, **cluster_template_dict)
     self.cluster_template.create()
     bay_dict = utils.get_test_bay(node_count=1)
     self.bay = objects.Bay(self.context, **bay_dict)
     self.bay.create()
    def setUp(self):
        super(MonitorsTestCase, self).setUp()

        bay = utils.get_test_bay(node_addresses=["1.2.3.4"], api_address="https://5.6.7.8:2376")
        self.bay = objects.Bay(self.context, **bay)
        self.monitor = swarm_monitor.SwarmMonitor(self.context, self.bay)
        self.k8s_monitor = k8s_monitor.K8sMonitor(self.context, self.bay)
        p = mock.patch("magnum.conductor.swarm_monitor.SwarmMonitor." "metrics_spec", new_callable=mock.PropertyMock)
        self.mock_metrics_spec = p.start()
        self.mock_metrics_spec.return_value = self.test_metrics_spec
        self.addCleanup(p.stop)
Exemple #25
0
    def setUp(self):
        super(MonitorsTestCase, self).setUp()

        bay = utils.get_test_bay(node_addresses=['1.2.3.4'],
                                 api_address='5.6.7.8')
        self.bay = objects.Bay(self.context, **bay)
        self.monitor = monitors.SwarmMonitor(self.context, self.bay)
        p = mock.patch('magnum.conductor.monitors.SwarmMonitor.metrics_spec',
                       new_callable=mock.PropertyMock)
        self.mock_metrics_spec = p.start()
        self.mock_metrics_spec.return_value = self.test_metrics_spec
        self.addCleanup(p.stop)
Exemple #26
0
 def setUp(self):
     super(TestBayObject, self).setUp()
     self.fake_bay = utils.get_test_bay()
     self.fake_bay['trust_id'] = 'trust_id'
     self.fake_bay['trustee_username'] = '******'
     self.fake_bay['trustee_user_id'] = 'trustee_user_id'
     self.fake_bay['trustee_password'] = '******'
     self.fake_bay['coe_version'] = 'fake-coe-version'
     self.fake_bay['container_version'] = 'fake-container-version'
     cluster_template_id = self.fake_bay['baymodel_id']
     self.fake_cluster_template = objects.ClusterTemplate(
         uuid=cluster_template_id)
Exemple #27
0
    def setUp(self):
        super(MonitorsTestCase, self).setUp()

        bay = utils.get_test_bay(node_addresses=['1.2.3.4'],
                                 api_address='5.6.7.8')
        self.bay = objects.Bay(self.context, **bay)
        self.monitor = monitors.SwarmMonitor(self.context, self.bay)
        p = mock.patch('magnum.conductor.monitors.SwarmMonitor.metrics_spec',
                       new_callable=mock.PropertyMock)
        self.mock_metrics_spec = p.start()
        self.mock_metrics_spec.return_value = self.test_metrics_spec
        self.addCleanup(p.stop)
Exemple #28
0
    def test_get_service_list_with_filters(self):
        bay1 = utils.get_test_bay(id=11, uuid=magnum_utils.generate_uuid())
        bay2 = utils.get_test_bay(id=12, uuid=magnum_utils.generate_uuid())
        self.dbapi.create_bay(bay1)
        self.dbapi.create_bay(bay2)

        service1 = utils.create_test_service(
            name='service-one',
            uuid=magnum_utils.generate_uuid(),
            bay_uuid=bay1['uuid'],
            ports=[{'port': 8000}])
        service2 = utils.create_test_service(
            name='service-two',
            uuid=magnum_utils.generate_uuid(),
            bay_uuid=bay2['uuid'],
            ports=[{'port': 8001}])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'bay_uuid': bay1['uuid']})
        self.assertEqual([service1.id], [r.id for r in res])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'bay_uuid': bay2['uuid']})
        self.assertEqual([service2.id], [r.id for r in res])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'name': 'service-one'})
        self.assertEqual([service1.id], [r.id for r in res])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'name': 'bad-service'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'ports': [{'port': 8000}]})
        self.assertEqual([service1.id], [r.id for r in res])

        res = self.dbapi.get_service_list(self.context,
                                          filters={'ports': [{'port': 8001}]})
        self.assertEqual([service2.id], [r.id for r in res])
Exemple #29
0
    def test_get_pod_list_with_filters(self):
        bay1 = utils.get_test_bay(id=11, uuid=magnum_utils.generate_uuid())
        bay2 = utils.get_test_bay(id=12, uuid=magnum_utils.generate_uuid())
        self.dbapi.create_bay(bay1)
        self.dbapi.create_bay(bay2)

        pod1 = utils.create_test_pod(
            name='pod-one',
            uuid=magnum_utils.generate_uuid(),
            bay_uuid=bay1['uuid'],
            status='status1')
        pod2 = utils.create_test_pod(
            name='pod-two',
            uuid=magnum_utils.generate_uuid(),
            bay_uuid=bay2['uuid'],
            status='status2')

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'bay_uuid': bay1['uuid']})
        self.assertEqual([pod1.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'bay_uuid': bay2['uuid']})
        self.assertEqual([pod2.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'name': 'pod-one'})
        self.assertEqual([pod1.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'name': 'bad-pod'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'status': 'status1'})
        self.assertEqual([pod1.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'status': 'status2'})
        self.assertEqual([pod2.id], [r.id for r in res])
Exemple #30
0
    def test_get_pod_list_with_filters(self):
        bay1 = utils.get_test_bay(id=11, uuid=magnum_utils.generate_uuid())
        bay2 = utils.get_test_bay(id=12, uuid=magnum_utils.generate_uuid())
        self.dbapi.create_bay(bay1)
        self.dbapi.create_bay(bay2)

        pod1 = utils.create_test_pod(name='pod-one',
                                     uuid=magnum_utils.generate_uuid(),
                                     bay_uuid=bay1['uuid'],
                                     status='status1')
        pod2 = utils.create_test_pod(name='pod-two',
                                     uuid=magnum_utils.generate_uuid(),
                                     bay_uuid=bay2['uuid'],
                                     status='status2')

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'bay_uuid': bay1['uuid']})
        self.assertEqual([pod1.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'bay_uuid': bay2['uuid']})
        self.assertEqual([pod2.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'name': 'pod-one'})
        self.assertEqual([pod1.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'name': 'bad-pod'})
        self.assertEqual([], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'status': 'status1'})
        self.assertEqual([pod1.id], [r.id for r in res])

        res = self.dbapi.get_pod_list(self.context,
                                      filters={'status': 'status2'})
        self.assertEqual([pod2.id], [r.id for r in res])
Exemple #31
0
def get_test_bay(context, **kw):
    """Return a Bay object with appropriate attributes.

    NOTE: The object leaves the attributes marked as changed, such
    that a create() could be used to commit it to the DB.
    """
    db_bay = db_utils.get_test_bay(**kw)
    # Let DB generate ID if it isn't specified explicitly
    if 'id' not in kw:
        del db_bay['id']
    bay = objects.Bay(context)
    for key in db_bay:
        setattr(bay, key, db_bay[key])
    return bay
Exemple #32
0
    def setUp(self):
        super(MonitorsTestCase, self).setUp()

        bay = utils.get_test_bay(node_addresses=['1.2.3.4'],
                                 api_address='https://5.6.7.8:2376',
                                 master_addresses=['10.0.0.6'])
        self.bay = objects.Bay(self.context, **bay)
        self.monitor = swarm_monitor.SwarmMonitor(self.context, self.bay)
        self.k8s_monitor = k8s_monitor.K8sMonitor(self.context, self.bay)
        self.mesos_monitor = mesos_monitor.MesosMonitor(self.context,
                                                        self.bay)
        p = mock.patch('magnum.conductor.swarm_monitor.SwarmMonitor.'
                       'metrics_spec', new_callable=mock.PropertyMock)
        self.mock_metrics_spec = p.start()
        self.mock_metrics_spec.return_value = self.test_metrics_spec
        self.addCleanup(p.stop)
Exemple #33
0
    def setUp(self):
        super(MonitorsTestCase, self).setUp()

        bay = utils.get_test_bay(node_addresses=['1.2.3.4'],
                                 api_address='https://5.6.7.8:2376',
                                 master_addresses=['10.0.0.6'])
        self.bay = objects.Bay(self.context, **bay)
        self.monitor = swarm_monitor.SwarmMonitor(self.context, self.bay)
        self.k8s_monitor = k8s_monitor.K8sMonitor(self.context, self.bay)
        self.mesos_monitor = mesos_monitor.MesosMonitor(self.context, self.bay)
        p = mock.patch(
            'magnum.conductor.swarm_monitor.SwarmMonitor.'
            'metrics_spec',
            new_callable=mock.PropertyMock)
        self.mock_metrics_spec = p.start()
        self.mock_metrics_spec.return_value = self.test_metrics_spec
        self.addCleanup(p.stop)
    def setUp(self):
        super(TestHandler, self).setUp()
        self.handler = bay_conductor.Handler()
        baymodel_dict = utils.get_test_baymodel()
        self.baymodel = objects.BayModel(self.context, **baymodel_dict)
        self.baymodel.create()
        bay_dict = utils.get_test_bay(node_count=1)
        self.bay = objects.Bay(self.context, **bay_dict)
        self.bay.create()

        self.p = patch(
            'magnum.conductor.handlers.bay_conductor.Handler.'
            '_create_trustee_and_trust')

        def create_trustee_and_trust(osc, bay):
            bay.trust_id = 'trust_id'
            bay.trustee_username = '******'
            bay.trustee_user_id = 'user_id'
            bay.trustee_password = '******'

        self.p.side_effect = create_trustee_and_trust
        self.p.start()
Exemple #35
0
def bay_post_data(**kw):
    bay = utils.get_test_bay(**kw)
    bay['bay_create_timeout'] = kw.get('bay_create_timeout', 15)
    internal = bay_controller.BayPatchType.internal_attrs()
    return remove_internal(bay, internal)
 def setUp(self):
     super(TestHandler, self).setUp()
     self.handler = bay_k8s_heat.Handler()
     bay_dict = utils.get_test_bay(node_count=1)
     self.bay = objects.Bay(self.context, **bay_dict)
     self.bay.create()
Exemple #37
0
 def setUp(self):
     super(RPCAPITestCase, self).setUp()
     self.fake_bay = dbutils.get_test_bay(driver='fake-driver')
     self.fake_certificate = objects.Certificate.from_db_bay(self.fake_bay)
     self.fake_certificate.csr = 'fake-csr'
Exemple #38
0
def bay_post_data(**kw):
    bay = utils.get_test_bay(**kw)
    internal = bay_controller.BayPatchType.internal_attrs()
    return remove_internal(bay, internal)
Exemple #39
0
def bay_post_data(**kw):
    bay = utils.get_test_bay(**kw)
    bay['bay_create_timeout'] = kw.get('bay_create_timeout', 15)
    internal = bay_controller.BayPatchType.internal_attrs()
    return remove_internal(bay, internal)
Exemple #40
0
 def setUp(self):
     super(TestBayObject, self).setUp()
     self.fake_bay = utils.get_test_bay()
     baymodel_id = self.fake_bay['baymodel_id']
     self.fake_baymodel = objects.BayModel(uuid=baymodel_id)
Exemple #41
0
 def fake_get_by_uuid(context, uuid):
     return objects.Bay(self.context, **utils.get_test_bay(uuid=uuid))
Exemple #42
0
 def setUp(self):
     super(TestBayObject, self).setUp()
     self.fake_bay = utils.get_test_bay()
Exemple #43
0
 def fake_get_by_uuid(context, uuid):
     return objects.Bay(self.context, **utils.get_test_bay(uuid=uuid))
Exemple #44
0
from magnum.tests.unit.db import utils

periodic_opts = [
    cfg.BoolOpt('periodic_enable',
                default=True,
                help='Enable periodic tasks.'),
    cfg.IntOpt('periodic_interval_max',
               default=60,
               help='Max interval size between periodic tasks execution in '
                    'seconds.'),
]


ctx = context.make_admin_context()

bay1 = utils.get_test_bay(id=1, stack_id='11',
                          status=bay_status.CREATE_IN_PROGRESS)
bay2 = utils.get_test_bay(id=2, stack_id='22',
                          status=bay_status.DELETE_IN_PROGRESS)
bay3 = utils.get_test_bay(id=3, stack_id='33',
                          status=bay_status.UPDATE_IN_PROGRESS)

bay1 = objects.Bay(ctx, **bay1)
bay2 = objects.Bay(ctx, **bay2)
bay3 = objects.Bay(ctx, **bay3)


class fake_stack(object):
    def __init__(self, **kw):
        for key, val in kw.items():
            setattr(self, key, val)
Exemple #45
0
 def setUp(self):
     super(TestBayObject, self).setUp()
     self.fake_bay = utils.get_test_bay()
     baymodel_id = self.fake_bay["baymodel_id"]
     self.fake_baymodel = objects.BayModel(uuid=baymodel_id)
 def setUp(self):
     super(TestHandler, self).setUp()
     self.handler = bay_k8s_heat.Handler()
     bay_dict = utils.get_test_bay(node_count=1)
     self.bay = objects.Bay(self.context, **bay_dict)
     self.bay.create()
    def test_containers_api(self,
                            mock_container_execute,
                            mock_container_logs,
                            mock_container_reboot,
                            mock_container_unpause,
                            mock_container_pause,
                            mock_container_stop,
                            mock_container_start,
                            mock_container_delete,
                            mock_container_create,
                            mock_get_by_uuid):
        mock_container_create.side_effect = lambda x, y, z: z
        mock_container_start.return_value = None
        mock_container_stop.return_value = None
        mock_container_pause.return_value = None
        mock_container_unpause.return_value = None
        mock_container_reboot.return_value = None
        mock_container_logs.return_value = None
        mock_container_execute.return_value = None

        # Create a container
        params = ('{"name": "My Docker", "image_id": "ubuntu",'
                  '"command": "env",'
                  '"bay_uuid": "fff114da-3bfa-4a0f-a123-c0dffad9718e"}')
        self.fake_bay = utils.get_test_bay()
        value = self.fake_bay['uuid']
        mock_get_by_uuid.return_value = self.fake_bay
        bay = objects.Bay.get_by_uuid(self.context, value)
        self.assertEqual(value, bay['uuid'])
        response = self.app.post('/v1/containers',
                                 params=params,
                                 content_type='application/json')
        self.assertEqual(response.status_int, 201)

        # Get all containers
        response = self.app.get('/v1/containers')
        self.assertEqual(response.status_int, 200)
        self.assertEqual(1, len(response.json))
        c = response.json['containers'][0]
        self.assertIsNotNone(c.get('uuid'))
        self.assertEqual('My Docker', c.get('name'))

        # Get just the one we created
        response = self.app.get('/v1/containers/%s' % c.get('uuid'))
        self.assertEqual(response.status_int, 200)

        # Update the description
        params = [{'path': '/name',
                   'value': 'container_example_B',
                   'op': 'replace'}]
        response = self.app.patch_json('/v1/containers/%s' % c.get('uuid'),
                               params=params)
        self.assertEqual(response.status_int, 200)

        # Execute some actions
        actions = ['start', 'stop', 'pause', 'unpause',
                   'reboot']
        for action in actions:
            response = self.app.put('/v1/containers/%s/%s' % (c.get('uuid'),
                                                              action))
            self.assertEqual(response.status_int, 200)

            # Only PUT should work, others like GET should fail
            self.assertRaises(AppError, self.app.get,
                              ('/v1/containers/%s/%s' %
                               (c.get('uuid'), action)))

        # Fetch the logs
        response = self.app.get('/v1/containers/%s/logs' % c.get('uuid'))
        self.assertEqual(response.status_int, 200)

        # Fetch the logs should fail with put
        self.assertRaises(AppError, self.app.put,
                          ('/v1/containers/%s/logs' % c.get('uuid')))

        # Execute command in docker container
        response = self.app.put('/v1/containers/%s/%s' % (c.get('uuid'),
                                              'execute'), {'command': 'ls'})
        self.assertEqual(response.status_int, 200)

        # Delete the container we created
        response = self.app.delete('/v1/containers/%s' % c.get('uuid'))
        self.assertEqual(response.status_int, 204)

        response = self.app.get('/v1/containers')
        self.assertEqual(response.status_int, 200)
        c = response.json['containers']
        self.assertEqual(0, len(c))

        self.assertTrue(mock_container_create.called)
        self.assertTrue(mock_container_start.called)
        self.assertTrue(mock_container_stop.called)
        self.assertTrue(mock_container_pause.called)
        self.assertTrue(mock_container_unpause.called)
        self.assertTrue(mock_container_reboot.called)
        self.assertTrue(mock_container_logs.called)
        self.assertTrue(mock_container_execute.called)
Exemple #48
0
 def setUp(self):
     super(TestBayObject, self).setUp()
     self.fake_bay = utils.get_test_bay()