Skip to content

Commit

Permalink
Fix hardcoded scheduler (#1107)
Browse files Browse the repository at this point in the history
* * Remove hard-coded scheduler name.

* * Moving scheduler test files to subfolder.

* * Add test for full scheduler namespace.

* * Small cleanup to assumed base directory.
* Misc. cleanup.

* * Docker compose don't rely on $PANDIR.

* ** Unrelated to PR **

The `test_sdk_camera_not_found` is creating a camera class and then raising an exception with an invalid config, however the camera object is still in memory and not getting cleaned up by the garbage collector. This is causing a race condition on the `test_sdk_already_in_use` test, causing it to hang indefinitely in an odd way.  Simply moving the offending test below seems to fix the problem although it should probably be fixed more better.
  • Loading branch information
wtgee committed May 28, 2021
1 parent e79ac49 commit 23e151c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 18 deletions.
6 changes: 3 additions & 3 deletions conf_files/pocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ location:
gmt_offset: -600 # Offset in minutes from GMT during.

directories:
base: /panoptes-pocs
base: .
images: images
mounts: resources/mounts
fields: conf_files/fields
Expand All @@ -44,8 +44,8 @@ status_check_interval: 60 # periodic status check.
state_machine: panoptes

scheduler:
type: dispatch
fields_file: /panoptes-pocs/conf_files/targets/simple.yaml
type: panoptes.pocs.scheduler.dispatch
fields_file: simple.yaml
check_file: False

mount:
Expand Down
8 changes: 4 additions & 4 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,25 +53,25 @@ volumes:
driver: local
driver_opts:
type: none
device: ${PANDIR}/logs
device: ./logs
o: bind
images:
driver: local
driver_opts:
type: none
device: ${PANDIR}/images
device: ./images
o: bind
config:
driver: local
driver_opts:
type: none
device: ${PANDIR}/conf_files/
device: ./conf_files/
o: bind
json_store:
driver: local
driver_opts:
type: none
device: ${PANDIR}/json_store
device: ./json_store
o: bind
devices:
driver: local
Expand Down
9 changes: 4 additions & 5 deletions src/panoptes/pocs/scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def create_scheduler_from_config(observer=None, *args, **kwargs):
site_details = create_location_from_config()
observer = site_details['observer']

scheduler_type = scheduler_config.get('type', 'dispatch')
scheduler_type = scheduler_config.get('type', 'panoptes.pocs.scheduler.dispatch')

# Read the targets from the file
fields_file = scheduler_config.get('fields_file', 'simple.yaml')
Expand All @@ -44,11 +44,10 @@ def create_scheduler_from_config(observer=None, *args, **kwargs):

try:
# Load the required module
module = load_module(f'panoptes.pocs.scheduler.{scheduler_type}')
module = load_module(f'{scheduler_type}')

obstruction_list = get_config('location.obstructions', default=[])
default_horizon = get_config(
'location.horizon', default=30 * u.degree)
default_horizon = get_config('location.horizon', default=30 * u.degree)

horizon_line = horizon_utils.Horizon(
obstructions=obstruction_list,
Expand All @@ -71,6 +70,6 @@ def create_scheduler_from_config(observer=None, *args, **kwargs):
except error.NotFound as e:
raise error.NotFound(msg=e)
else:
raise error.NotFound(msg=f"Fields file does not exist: fields_file={fields_file!r}")
raise error.NotFound(msg=f"Fields file does not exist: {fields_path=!r}")

return scheduler
Empty file added tests/scheduler/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions tests/test_scheduler.py → tests/scheduler/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ def reset_conf(config_host, config_port):
assert response.ok


def test_bad_scheduler_namespace(config_host, config_port):
set_config('scheduler.type', 'dispatch')
site_details = create_location_from_config()
with pytest.raises(error.NotFound):
create_scheduler_from_config(observer=site_details['observer'])

set_config('scheduler.type', 'panoptes.pocs.scheduler.dispatch')
scheduler = create_scheduler_from_config(observer=site_details['observer'])

assert isinstance(scheduler, BaseScheduler)

reset_conf(config_host, config_port)


def test_bad_scheduler_type(config_host, config_port):
set_config('scheduler.type', 'foobar')
site_details = create_location_from_config()
Expand Down
10 changes: 5 additions & 5 deletions tests/test_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,6 @@ def test_sdk_no_serial_number():
SimSDKCamera()


def test_sdk_camera_not_found():
with pytest.raises(error.InvalidConfig):
SimSDKCamera(serial_number='SSC404')


def test_sdk_already_in_use():
serial_number = get_config('cameras.devices[-1].serial_number')
sim_camera = SimSDKCamera(serial_number=serial_number)
Expand All @@ -193,6 +188,11 @@ def test_sdk_already_in_use():
SimSDKCamera(serial_number=serial_number)


def test_sdk_camera_not_found():
with pytest.raises(error.InvalidConfig):
SimSDKCamera(serial_number='SSC404')


# Hardware independent tests for SBIG camera


Expand Down
2 changes: 1 addition & 1 deletion tests/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ db:
name: panoptes_testing
type: file
scheduler:
type: dispatch
type: panoptes.pocs.scheduler.dispatch
fields_file: simulator.yaml
check_file: False
mount:
Expand Down

0 comments on commit 23e151c

Please sign in to comment.