private Cluster createUpgradeCluster(
      RepositoryVersionEntity sourceRepoVersion, String hostName) throws Exception {

    clusters.addCluster(clusterName, sourceRepoVersion.getStackId());
    Cluster cluster = clusters.getCluster(clusterName);

    // add a host component
    clusters.addHost(hostName);

    Host host = clusters.getHost(hostName);

    Map<String, String> hostAttributes = new HashMap<>();
    hostAttributes.put("os_family", "redhat");
    hostAttributes.put("os_release_version", "6");
    host.setHostAttributes(hostAttributes);

    // without this, HostEntity will not have a relation to ClusterEntity
    clusters.mapHostToCluster(hostName, clusterName);

    HostVersionEntity entity = new HostVersionEntity(hostDAO.findByName(hostName),
        sourceRepoVersion, RepositoryVersionState.INSTALLED);

    hostVersionDAO.create(entity);

    return cluster;
  }
Tests upgrade-related server side actions
ambari-server/src/test/java/org/apache/ambari/server/serveraction/upgrades/UpgradeActionTest.java