def test_hbs_update_property(self):
     project2 = Project('project2-%s' % self.id())
     project2.set_quota(QuotaType(host_based_service=1))
     self.api.project_create(project2)
     hbs = HostBasedService('hbs1-%s' % self.id(), parent_obj=project2)
     self.api.host_based_service_create(hbs)
     hbs.set_display_name('new display name')
     self.api.host_based_service_update(hbs)
 def test_hbs_create_with_mgmt_vn_ref(self):
     project2 = Project('project2-%s' % self.id())
     project2.set_quota(QuotaType(host_based_service=1))
     self.api.project_create(project2)
     vn1 = VirtualNetwork('vn1-%s' % self.id(), parent_obj=project2)
     self.api.virtual_network_create(vn1)
     hbs1 = HostBasedService('hbs1-%s' % self.id(), parent_obj=project2)
     hbs1.add_virtual_network(vn1, ServiceVirtualNetworkType('management'))
     self.api.host_based_service_create(hbs1)
 def test_hbs_create_with_annotations(self):
     project2 = Project('project2-%s' % self.id())
     project2.set_quota(QuotaType(host_based_service=1))
     self.api.project_create(project2)
     vn1 = VirtualNetwork('vn1-%s' % self.id(), parent_obj=project2)
     self.api.virtual_network_create(vn1)
     hbs1 = HostBasedService('hbs1-%s' % self.id(), parent_obj=project2)
     hbs1.add_annotations(KeyValuePair(
         key='image', value='hub.juniper.net/security/csrx:19.2R1.8'))
     hbs1.add_annotations(KeyValuePair(key='imagePullSecrets', value='psd'))
     self.api.host_based_service_create(hbs1)
    def test_host_based_resource_limited_to_one_per_project(self):
        project2 = Project('project2-%s' % self.id())
        self.api.project_create(project2)

        hbs1 = HostBasedService('hbs1-%s' % self.id(), parent_obj=project2)
        self.assertRaises(OverQuota, self.api.host_based_service_create, hbs1)

        project2.set_quota(QuotaType(host_based_service=1))
        self._vnc_lib.project_update(project2)

        hbs1 = HostBasedService('hbs1-%s' % self.id(), parent_obj=project2)
        self.api.host_based_service_create(hbs1)

        hbs2 = HostBasedService('hbs2-%s' % self.id(), parent_obj=project2)
        self.assertRaises(OverQuota, self.api.host_based_service_create, hbs2)

        project2.set_quota(QuotaType(host_based_service=2))
        self.assertRaises(BadRequest, self._vnc_lib.project_update, project2)

        project2.set_quota(QuotaType(host_based_service=-1))
        self.assertRaises(BadRequest, self._vnc_lib.project_update, project2)

        project2.set_quota(QuotaType(host_based_service=None))
        self._vnc_lib.project_update(project2)
        self.assertRaises(OverQuota, self.api.host_based_service_create, hbs2)
 def test_hbs_update_default_vn_property(self):
     project2 = Project('project2-%s' % self.id())
     project2.set_quota(QuotaType(host_based_service=1))
     self.api.project_create(project2)
     hbs = HostBasedService('hbs1-%s' % self.id(), parent_obj=project2)
     self.api.host_based_service_create(hbs)
     hbs = self.api.host_based_service_read(id=hbs.uuid)
     vn_ref_left_uuid = hbs.virtual_network_refs[0]['uuid']
     self.assertRaises(
         BadRequest,
         self.api.ref_update,
         hbs.resource_type,
         hbs.uuid,
         'virtual_network',
         vn_ref_left_uuid,
         None,
         'ADD',
         ServiceVirtualNetworkType('management'),
     )
    def test_get_hbs_template_no_json(self):
        project2 = Project('project2-%s' % self.id())
        project2.set_quota(QuotaType(host_based_service=1))

        kvp_array = []
        kvp = KeyValuePair("namespace", "k8test")
        kvp_array.append(kvp)
        kvp = KeyValuePair("cluster", "c1")
        kvp_array.append(kvp)
        kvps = KeyValuePairs()
        kvps.set_key_value_pair(kvp_array)

        project2.set_annotations(kvps)

        self.api.project_create(project2)
        hbs = HostBasedService('hbs-%s' % self.id(), parent_obj=project2)
        self.api.host_based_service_create(hbs)

        (code, msg) = self._http_post('/hbs-get', None)
        self.assertEquals(code, 400)
 def setUp(self):
     super(TestHostBasedService, self).setUp()
     project = Project('project-%s' % self.id())
     project.set_quota(QuotaType(host_based_service=1))
     self.api.project_create(project)
     self.project = self.api.project_read(id=project.uuid)