Exemplo n.º 1
0
 def validate_status(self, status):
     status = status.upper()
     names = RegionStatusEnum.names()
     if status not in names:
         raise serializers.ValidationError("不支持状态: '{}', 仅支持: {}".format(
             status, ",".join(names)))
     return status
def test_region_status_to_dict():
    d = RegionStatusEnum.to_dict()

    assert isinstance(d, dict)
    assert len(d) == 4
    assert d["NOTREADY"] == 0
    assert d["ONLINE"] == 1
    assert d["OFFLINE"] == 2
    assert d["MAINTAIN"] == 3
    assert "ONLINE" == RegionStatusEnum.ONLINE.name
Exemplo n.º 3
0
    def update_region_status(self, region_id, status):
        region = region_repo.get_region_by_region_id(region_id)

        stauts_tbl = RegionStatusEnum.to_dict()
        status = status.upper()
        region.status = stauts_tbl[status]

        if status == RegionStatusEnum.ONLINE.name:
            try:
                region_api.get_api_version(region.url, region.token, region.region_name)
            except region_api.CallApiError as e:
                logger.warning("数据中心{0}不可达,无法上线: {1}".format(region.region_name, e.message))
                raise RegionUnreachableError("数据中心{0}不可达,无法上线".format(region.region_name))

        region.save()
        self.update_region_config()
        return region
def test_region_status_names():
    names = RegionStatusEnum.names()

    assert isinstance(names, list)
    assert len(names) == 4