Skip to content

Commit

Permalink
feat(dp): Remove grant attempts (#13394)
Browse files Browse the repository at this point in the history
Grant attemts have been obsolete since carrier aggregation was introduced.

Signed-off-by: Kuba Marciniszyn <kuba@freedomfi.com>
  • Loading branch information
jkmar committed Jul 25, 2022
1 parent 1b7a055 commit cca60f1
Show file tree
Hide file tree
Showing 15 changed files with 233 additions and 267 deletions.
324 changes: 157 additions & 167 deletions dp/cloud/go/active_mode_controller/protos/active_mode/active_mode.pb.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dp/cloud/go/services/dp/storage/cbsd_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func buildDetailedCbsdQuery(builder sq.StatementBuilderType) *db.Query {
WithBuilder(builder).
From(&DBCbsd{}).
Select(db.NewExcludeMask("network_id", "state_id", "desired_state_id",
"is_deleted", "should_deregister", "grant_attempts")).
"is_deleted", "should_deregister")).
Join(db.NewQuery().
From(&DBCbsdState{}).
As("t1").
Expand Down
5 changes: 2 additions & 3 deletions dp/cloud/go/services/dp/storage/cbsd_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ func (s *CbsdManagerTestSuite) verifyCbsdCreation(expected *storage.DBCbsd) {

cbsd := expected
cbsd.NetworkId = db.MakeString(someNetwork)
cbsd.GrantAttempts = db.MakeInt(0)
cbsd.IsDeleted = db.MakeBool(false)
cbsd.ShouldDeregister = db.MakeBool(false)
expected := []db.Model{
Expand Down Expand Up @@ -235,7 +234,7 @@ func (s *CbsdManagerTestSuite) TestUpdateCbsd() {
WithBuilder(s.resourceManager.GetBuilder()).
From(&storage.DBCbsd{}).
Select(db.NewExcludeMask("id", "state_id",
"cbsd_id", "grant_attempts", "is_deleted")).
"cbsd_id", "is_deleted")).
Where(sq.Eq{"id": someCbsdId}).
Fetch()
s.Require().NoError(err)
Expand Down Expand Up @@ -372,7 +371,7 @@ func (s *CbsdManagerTestSuite) TestEnodebdUpdateCbsd() {
WithBuilder(s.resourceManager.GetBuilder()).
From(&storage.DBCbsd{}).
Select(db.NewExcludeMask("id", "state_id",
"cbsd_id", "grant_attempts", "is_deleted")).
"cbsd_id", "is_deleted")).
Where(sq.Eq{"cbsd_serial_number": tc.input.CbsdSerialNumber}).
Fetch()
s.Require().NoError(err)
Expand Down
8 changes: 0 additions & 8 deletions dp/cloud/go/services/dp/storage/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ type DBCbsd struct {
FccId sql.NullString
CbsdSerialNumber sql.NullString
LastSeen sql.NullTime
GrantAttempts sql.NullInt64
PreferredBandwidthMHz sql.NullInt64
PreferredFrequenciesMHz sql.NullString
MinPower sql.NullFloat64
Expand Down Expand Up @@ -251,7 +250,6 @@ func (c *DBCbsd) Fields() []db.BaseType {
db.StringType{X: &c.FccId},
db.StringType{X: &c.CbsdSerialNumber},
db.TimeType{X: &c.LastSeen},
db.IntType{X: &c.GrantAttempts},
db.IntType{X: &c.PreferredBandwidthMHz},
db.StringType{X: &c.PreferredFrequenciesMHz},
db.FloatType{X: &c.MinPower},
Expand Down Expand Up @@ -328,12 +326,6 @@ func (c *DBCbsd) GetMetadata() *db.ModelMetadata {
SqlType: sqorc.ColumnTypeDatetime,
Nullable: true,
},
{
Name: "grant_attempts",
SqlType: sqorc.ColumnTypeInt,
HasDefault: true,
DefaultValue: 0,
},
{
Name: "preferred_bandwidth_mhz",
SqlType: sqorc.ColumnTypeInt,
Expand Down
7 changes: 0 additions & 7 deletions dp/cloud/go/services/dp/storage/models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ func TestFields(t *testing.T) {
db.StringType{X: &dbCbsd.FccId},
db.StringType{X: &dbCbsd.CbsdSerialNumber},
db.TimeType{X: &dbCbsd.LastSeen},
db.IntType{X: &dbCbsd.GrantAttempts},
db.IntType{X: &dbCbsd.PreferredBandwidthMHz},
db.StringType{X: &dbCbsd.PreferredFrequenciesMHz},
db.FloatType{X: &dbCbsd.MinPower},
Expand Down Expand Up @@ -265,12 +264,6 @@ func TestGetMetadata(t *testing.T) {
SqlType: sqorc.ColumnTypeDatetime,
Nullable: true,
},
{
Name: "grant_attempts",
SqlType: sqorc.ColumnTypeInt,
HasDefault: true,
DefaultValue: 0,
},
{
Name: "preferred_bandwidth_mhz",
SqlType: sqorc.ColumnTypeInt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ def process_grant_response(obj: ResponseDBProcessor, response: DBResponse, sessi

if response.response_code != ResponseCodes.SUCCESS.value:
cbsd = response.request.cbsd
if cbsd:
cbsd.grant_attempts += 1

grant = _get_or_create_grant_from_response(obj, response, session)
if not grant:
Expand Down Expand Up @@ -363,8 +361,6 @@ def _terminate_all_grants_from_response(response: DBResponse, session: Session)
if not cbsd_id:
return
cbsd = session.query(DBCbsd).filter(DBCbsd.cbsd_id == cbsd_id).scalar()
if cbsd:
cbsd.grant_attempts = 0
logger.info(f'Terminating all grants for {cbsd_id=}')
session.query(DBGrant).filter(DBGrant.cbsd == cbsd).delete()
logger.info(f"Deleting all channels for {cbsd_id=}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@
GRANT_REQ = RequestTypes.GRANT.value
SPECTRUM_INQ_REQ = RequestTypes.SPECTRUM_INQUIRY.value

INITIAL_GRANT_ATTEMPTS = 1

_fake_requests_map = {
REGISTRATION_REQ: registration_requests,
SPECTRUM_INQ_REQ: spectrum_inquiry_requests,
Expand Down Expand Up @@ -189,47 +187,6 @@ def test_grant_state_after_response(
[g.state.name for g in self.session.query(DBGrant).all()],
)

@parameterized.expand([
(0, GRANT_REQ, INITIAL_GRANT_ATTEMPTS),
(400, GRANT_REQ, INITIAL_GRANT_ATTEMPTS + 1),
(401, GRANT_REQ, INITIAL_GRANT_ATTEMPTS + 1),
(0, RELINQUISHMENT_REQ, INITIAL_GRANT_ATTEMPTS),
(0, DEREGISTRATION_REQ, 0),
(0, SPECTRUM_INQ_REQ, 0),
])
@responses.activate
def test_grant_attempts_after_response(self, code, message_type, expected):
cbsd = DBCbsd(
cbsd_id=CBSD_ID,
user_id=USER_ID,
fcc_id=FCC_ID,
cbsd_serial_number=CBSD_SERIAL_NR,
grant_attempts=INITIAL_GRANT_ATTEMPTS,
state=self._get_db_enum(DBCbsdState, CbsdStates.REGISTERED.value),
desired_state=self._get_db_enum(DBCbsdState, CbsdStates.REGISTERED.value),
)
request = DBRequest(
type=self._get_db_enum(DBRequestType, message_type),
cbsd=cbsd,
payload={'cbsdId': CBSD_ID},
)

response = self._prepare_response_from_db_requests(
db_requests=[request],
response_code=code,
)

self.session.add(request)
self.session.commit()

self._process_response(
request_type_name=message_type,
response=response,
db_requests=[request],
)

self.assertEqual(expected, cbsd.grant_attempts)

@parameterized.expand([
(0, CbsdStates.REGISTERED),
(300, CbsdStates.UNREGISTERED),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""empty message
Revision ID: 58a1b16ef73c
Revises: 530b18568ad9
Create Date: 2022-07-22 16:03:01.235285
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = '58a1b16ef73c'
down_revision = '530b18568ad9'
branch_labels = None
depends_on = None


def upgrade():
"""
Run upgrade
"""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('cbsds', 'grant_attempts')
# ### end Alembic commands ###


def downgrade():
"""
Run downgrade
"""
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('cbsds', sa.Column('grant_attempts', sa.INTEGER(), server_default=sa.text('0'), autoincrement=False, nullable=False))
# ### end Alembic commands ###
1 change: 0 additions & 1 deletion dp/cloud/python/magma/db_service/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ class DBCbsd(Base):
max_power = Column(Float)
antenna_gain = Column(Float)
number_of_ports = Column(Integer)
grant_attempts = Column(Integer, nullable=False, server_default='0')
preferred_bandwidth_mhz = Column(
Integer, nullable=False, server_default='0',
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Copyright 2022 The Magma Authors.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from magma.db_service.tests.alembic_testcase import AlembicTestCase

TABLE = 'cbsds'
COLUMN = 'grant_attempts'


class RemoveGrantAttemptsTestCase(AlembicTestCase):
down_revision = '530b18568ad9'
up_revision = '58a1b16ef73c'

def setUp(self) -> None:
super().setUp()
self.upgrade(self.down_revision)

def test_upgrade(self):
self.upgrade()
self.assertFalse(self.has_column(self.get_table(TABLE), COLUMN))

def test_columns_present_post_upgrade(self):
self.upgrade()
self.downgrade()
self.assertTrue(self.has_column(self.get_table(TABLE), COLUMN))
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ def _build_cbsd(cbsd: DBCbsd) -> Cbsd:
channels=channels,
last_seen_timestamp=last_seen,
eirp_capabilities=eirp_capabilities,
grant_attempts=cbsd.grant_attempts,
db_data=db_data,
preferences=preferences,
sas_settings=sas_settings,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ def __init__(self):
self.grants = []
self.channels = []
self.last_seen_timestamp = None
self.grant_attempts = None
self.eirp_capabilities = EirpCapabilities()
self.sas_settings = SasSettings()
self.preferences = FrequencyPreferences()
Expand All @@ -55,7 +54,6 @@ def build(self) -> Cbsd:
grants=self.grants,
channels=self.channels,
last_seen_timestamp=self.last_seen_timestamp,
grant_attempts=self.grant_attempts,
eirp_capabilities=self.eirp_capabilities,
db_data=self.db_data,
preferences=self.preferences,
Expand Down Expand Up @@ -178,7 +176,3 @@ def make_optional_float(value: Optional[float] = None) -> FloatValue:
def with_last_seen(self, last_seen_timestamp: int) -> ActiveModeCbsdBuilder:
self.last_seen_timestamp = last_seen_timestamp
return self

def with_grant_attempts(self, grant_attempts: int) -> ActiveModeCbsdBuilder:
self.grant_attempts = grant_attempts
return self
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ def with_last_seen(self, last_seen: int) -> DBCbsdBuilder:
self.cbsd.last_seen = datetime.fromtimestamp(last_seen)
return self

def with_grant_attempts(self, grant_attempts: int) -> DBCbsdBuilder:
self.cbsd.grant_attempts = grant_attempts
return self

def with_desired_state(self, desired_state_id: int) -> DBCbsdBuilder:
self.cbsd.desired_state_id = desired_state_id
return self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,21 +306,6 @@ def test_get_state_with_last_seen(self):
actual = self.amc_service.GetState(GetStateRequest(), None)
self.assertEqual(expected, actual)

def test_get_state_with_grant_attempts(self):
cbsd = self._prepare_base_cbsd(). \
with_grant_attempts(1). \
build()
self.session.add(cbsd)
self.session.commit()

am_cbsd = self._prepare_base_active_mode_cbsd(). \
with_grant_attempts(1). \
build()
expected = State(cbsds=[am_cbsd])

actual = self.amc_service.GetState(GetStateRequest(), None)
self.assertEqual(expected, actual)

def test_get_state_with_pending_requests(self):
cbsd = self._prepare_base_cbsd(). \
with_request(self.grant, '{"key2":"value2"}'). \
Expand Down
13 changes: 6 additions & 7 deletions dp/protos/active_mode.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,12 @@ message Cbsd {
repeated Grant grants = 4;
repeated Channel channels = 5;
int64 last_seen_timestamp = 6;
int32 grant_attempts = 7;
SasSettings sas_settings = 8;
InstallationParams installation_params = 9;
EirpCapabilities eirp_capabilities = 10;
DatabaseCbsd db_data = 11;
FrequencyPreferences preferences = 12;
GrantSettings grant_settings = 13;
SasSettings sas_settings = 7;
InstallationParams installation_params = 8;
EirpCapabilities eirp_capabilities = 9;
DatabaseCbsd db_data = 10;
FrequencyPreferences preferences = 11;
GrantSettings grant_settings = 12;
}

message SasSettings {
Expand Down

0 comments on commit cca60f1

Please sign in to comment.